- Home /
Bullet synchronization via Photon Network doesnt work.
Hey, Im new to Unity and Photon Network. Im trying to make a skillshot shooter with bouncing bullets. The problem is the synchronization between the clients. First I tried no Network Instantiate every bullet and synchronize the positions with the Photon View Component. This was very inaccurate. The next thing I tried was instantiating the bullets via RPC calls on every client. This works until a player touches the bullet . The player is Network Instantiated, therefore his position is lerped and not 100% the same on the clients, leading to unsynchronized bullet . What do I miss? Whats the best way to approach this problem?
What I always do is instantiate bullets via RPC and then check for a hit on the client machine which shot the bullet. That way, if he hit the player on his machine, he get's the point. It is vulnerable to hacking, but it's more fair for a shooting player.
the problem is, the bullets continues flying after the hit.
If your Bullet hits a player call the function PlayerHit() with the hit player as parameter:
void PlayerHit(GameObject hitPlayer){
PhotonNetwork.RPC(photonView, "$$anonymous$$illPlayerAndBullet", PhotonTargets.All, hitPlayer.name);
}
[RPC]
void $$anonymous$$illPlayerAndBullet (string PlayerName){
Destroy (GameObject.Find (PlayerName));
Destroy (gameObject);
}
Place this function into a script which inherits from Photon.$$anonymous$$onoBehaviour and place that script onto the Bullet prefab.
It seems like you dont understand the problem. The bullet is meant to continue flying. But when it hits a player its stops being synchron.