I’ve been studying the Unity Netcode guide and different associated articles, which explains very clearly why it’s important to care about latency. Nonetheless, I have not seen good examples of implementing an answer. Under is a fast video of a bare-bones venture merely reproducing the difficulty. I’m utilizing an area host/shopper mannequin, with a simulated 70ms of delay, and you may see on the shopper aspect the bullets at all times spawn outdoors the participant, which I perceive why, however how do I am going about fixing it. I’m cannot discover good examples coping with the difficulty.
Video right here: https://youtu.be/ZuX2f2s3w3o
Right here is the code that spawns the bullets:
utilizing Unity.Netcode;
utilizing UnityEngine;
public class PlayerAttacks : NetworkBehaviour
{
public GameObject projectile;
public float FireRate;
float _nextShot;
void Replace()
{
if (!IsOwner) return;
if (Enter.GetKey(KeyCode.House))
{
if (_nextShot <= Time.time)
{
if (IsServer)
{
SpawnProjectile();
}
else
{
SpawnServerRpc();
}
_nextShot = 1 / FireRate + Time.time;
}
}
}
[ServerRpc]
void SpawnServerRpc()
{
SpawnProjectile();
}
void SpawnProjectile()
{
var p = Instantiate(projectile, rework.place, rework.rotation);
p.GetComponent<NetworkObject>().Spawn();
Destroy(p, 4f);
}
}