I am making a multiplayer arena game heavily inspired by halo. When a player dies, their weapons (1 or 2 guns) are dropped from their body.
I figured out how to smooth the position across the network, however, when a weapon is dropped from a high surface, the gun glitches out between positions. I added a fix that allows the gun to eventually go to the ground w/correct positioning and rotation (via raycast downwards and distance checks). The problem here is that it looks very glitchy and buggy while the gun is falling in the air.
Typically when the gun is “dropping”, it uses Vector3.Lerp(weapon pos, realPos (sent by argument), and 0.1f). This works fine and is smooth. The problem arises when the gun is midair after a high drop.
Any suggestions to what I should do?
Thanks,
Chris
Use the built in physics instead
Can you be a little more specific? Do you mean something like, when the weapon is dropping, change the NetworkTransform sync mode to SyncRigidbody3D instead of SyncTransform?
It sounds like your are trying to solve the problems with your own physics, with raycasting etc. Better to use Rigidbody and then sync that
Ok, I’ll try that, thanks
So the problem is not that it doesn’t sync. The problem is that it’s not smooth (i think thats the correct term?) while its falling from a tall height.
What I did for your suggestion was change the NetTransform to sync rigidbody3d when the gun calculated that it was a drop from a high height. While it looked kinda better, it was still glitchy at the end of the drop.
Any other suggestions to what I could do? Maybe the sync rigidbody3d will work, but I just have to edit some values like interpolation rate?
Interpolation alone doesn’t do it for physics : unless you have crazy low ping, and crazy high server perforamance and update frequency, it’s simply too “fast” and requires too much “reactivity” to look good.
You need extrapolation too. As its name implies, instead of lerping between two positions the server gave you, you take the last state of the object the server gave you (its position & rotation) and you let the client try and determine what will happen next without waiting for the server to tell it. If it predicts correctly, good ! You have a smooth change of state without any jiterring due to sudden changes in “wanted position”. If it doesn’t predict correctly, which is pretty rare in a lot of scenarios ran by very deterministic things, then you still correct it afterwards.
How do we apply that to your case ? Simple ! When the client knows an object is dropped, it adds a rigidbody to it and lets it fall as if it was a singleplayer game.The fall of an object in a given environment with a given starting position is pretty much completely deterministic, which means that the client will probably “predict” the exact same thing as the server, which will lead to 0 jittering while being accurate with the server and what other clients see at the same time.
Ok, awesome, that makes sense. I’ll try that and let you know how it goes.
Wow haha I had to do almost nothing. I had everything you suggested, I just had to get rid of the 2 Vector3.Lerp lines of code. There’s a few “safety” tweaks I need to make to ensure that it’s accurate as often as possible, but besides that, everything is working well.
Thanks for your help, man, i really appreciate it!
You welcome ! You’ll see, networking is full of these little tricks which I imagine are well known among the experts but that we amateurs / low experience pros must re-discover for ourselves. A piece of advice : go take a look at how networking works on other games which achieve the same things as what you want. Especially for games that are a bit older, you’ll usually find something on the web that describes it in detail. There you can find some of those tricks.