- Home /
Photon Network collision not accurate
I have Gameobjects (projectiles) that are instantiated from clients. These projectiles have not too much speed:
transform.Translate(Vector3.forward * Time.deltaTime * 15);
Each projectile has a photon view that keeps track of the current position and rotation with the following code:
transform.position = Vector3.Lerp(transform.position, realPosition, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, Time.deltaTime * 5);
My problem however is, each projectile has a OnCollisionEnter method which works fine, but the visuals aren't really well. On the client that has spawned the projectile, the projectile actually hits the other player, but for the other player the collision will trigger a lot before it actually hits which results in the other player thinking "Hey that didn't hit me!".
I assume this is because I'm not keeping track of the real position every frame, but how can I get closer to the real collision position without making the movement really jittery/laggy? How is this achieved in other games?
Thanks in advance!
Answer by alexi123454 · Jul 22, 2015 at 03:31 PM
Other games usually fake stuff like that, using a predicted trajectory for the projectile causing it to show up in the "real" place, even though that's not the position being received from the server.
An easy way to try getting the delay down is to increase the speed that you're Lerping at. The faster the lerp, the closer to the real position the bullet it. However, of course, the faster the lerp the more likely it is to jitter when receiving new positions from the server.
If you want to take the "fake" approach, you could make the bullet move a little faster than it normally does to compensate for the lag between the clients. Or, you could check at what time the bullet was fired, and then spawn the bullet a little ahead of where it was actually fired, depending on how far it should have moved since that time.
Your answer
![](https://koobas.hobune.stream/wayback/20220611232459im_/https://answers.unity.com/themes/thub/images/avi.jpg)