gpt4 book ai didi

c# - 玩家移动时与子弹碰撞 - Unity UNET

转载 作者:太空宇宙 更新时间:2023-11-03 23:19:30 25 4
gpt4 key购买 nike

设置:创建我的第一个多人游戏并遇到一个奇怪的问题。这是一款坦克游戏,玩家可以射击子弹并互相残杀

问题:当客户端移动时射击,子弹似乎有一点延迟产生,导致玩家与子弹相撞。

The issue seems to be that the player itself is local and the bullet is being spawned on the network ( which is causing the delay)

注意:主机播放器没有这个问题,因此它与网络有某种关系。

如何与客户端播放器同步子弹?

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);

}

最佳答案

您的游戏规则是否需要满足玩家的坦克能够自行射击的要求?

如果不是,一个简单的解决方案是让射弹的碰撞器在激活时忽略它所有者的碰撞器:

    Transform bullet = Instantiate(bulletPrefab) as Transform;
Physics.IgnoreCollision(bullet.GetComponent<Collider>(), GetComponent<Collider>());

关于c# - 玩家移动时与子弹碰撞 - Unity UNET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35904225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com