- Home /
Best way to synchronize projectile transform in networked game?
In my game each player can spawn projectiles. These projectiles get spawned on the server, they move on the server and handle collision on the server. For synchronizing the position and rotation, I use the Network Transform script with a Network Send Rate of 29 and the mode: Sync Rigidbody 3D.
The problem however is, even if a client has around 20 ping in milliseconds, the movement already gets a bit jittery. I tried writing my own script to lerp the movement, but resulted in the same thing.
What would be the best way to keep the movement smooth even if the client has a little bit of latency? In big games like League of Legends is the movement being mocked of projectiles? But how is the collision being handled? Thanks for reading!
Answer by srylain · Dec 08, 2015 at 09:11 AM
May be wrong, but I'd think your projectiles are jittery because they're not updating at the same frequency the game is since you're only sending the positions 29 times a second.
Not sure how doable it would be (and how well it would work with higher amounts of lag), but if you could send the start position of each projectile, its trajectory, and its speed you could get away with not having to send the positions over the network (although without more work this'll only work with projectiles that go in a straight line) by having the clients update the movement of the projectiles themselves.
You would then need to send a timestamp of when the shot was fired, so that when the clients receive that data they know how far ahead to put that projectile to account for ping. Depending on someone's lag, this will make the projectile appear farther away from where it should spawn the more lag someone has, but it'll at least let everyone see the projectile in the same place.
You'll still run all of the collision and everything on the server, and you could also do some collision on the client to tell when the projectile hit something so it doesn't go through it because of the delay between the server and client. But that's just if you want to hide some lag.
I haven't tried any of this, but it seems to me like it might work. If it does, it'll reduce quite a bit of network data too since you would normally be sending the transform of every projectile.
I've given the start position, speed and other variables to all clients (as SyncVar) and update the movement for each client individually and I must say it works quite fine even with a latency of around 40-50 ms. I indeed only handle collision on the server.
The only problem is that when for example having a ho$$anonymous$$g rocket (a projectile that does not only move forward in one direction). The target (SyncVar) of a ho$$anonymous$$g projectile has to be set on the server. I imagine If this target changes quite a couple of times, the position of the projectile will be not really accurate compared to the servers' projectile position.
Anyhow, I haven't really had a problem yet using this strategy so thanks for answering :)
Glad I could help. I haven't tried networking any sort of shooter yet (I've only done some small projects like Tetris and a Guitar Hero/Rock Band clone I made) and those games are surprisingly lag tolerant.
As for ho$$anonymous$$g projectiles though, unless your players can move really fast you should be able to update the projectiles in each client just fine. To hide the fact that the projectile could potentially miss on someone's screen, you could just have an explosion effect big enough to try and hide the lag.