【发布时间】:2016-06-24 13:45:55
【问题描述】:
设置:创建我的第一个多人游戏并遇到一个奇怪的问题。这是一款坦克游戏,玩家可以射击子弹并互相残杀
问题:当客户端在移动时射击时,子弹似乎会稍微延迟生成,这会导致玩家与子弹发生碰撞。
问题似乎是播放器本身是本地的,而子弹 正在网络上生成(导致延迟)
注意:主机播放器没有这个问题,因此它与网络有关。
如何将子弹与客户端播放器同步?
private void Fire(){
// Set the fired flag so only Fire is only called once.
m_Fired = true;
CmdCreateBullets ();
// Change the clip to the firing clip and play it.
m_ShootingAudio.clip = m_FireClip;
m_ShootingAudio.Play ();
// Reset the launch force. This is a precaution in case of missing button events.
m_CurrentLaunchForce = m_MinLaunchForce;
}
[Command]
private void CmdCreateBullets()
{
GameObject shellInstance = (GameObject)
Instantiate (m_Shell, m_FireTransform.position, m_FireTransform.rotation) ;
// Set the shell's velocity to the launch force in the fire position's forward direction.
shellInstance.GetComponent<Rigidbody>().velocity = m_CurrentLaunchForce * m_FireTransform.forward;
NetworkServer.Spawn (shellInstance);
}
【问题讨论】:
-
如果射弹是在服务器端创建的,它应该总是在玩家之前(在时间线中),但问题是由于玩家的对撞机在玩家收到弹丸的位置信息对吗?这是因为您在客户端执行碰撞检测吗?
-
完全正确,Hit 碰撞检测正在客户端完成
标签: c# networking unity3d unity3d-unet