- Home /
Authoritative Server: Run physics step manually?
I have a Server that does the following...
(Update) Receive inputs from clients
(FixedUpdate) Apply inputs to objects
(Internal) Simulate physics
(PostFixedUpdate) Send snapshot to clients
...and a Client that does the following...
(Update) Get input from user
(FixedUpdate) Apply input to user object
(Internal) Simulate physics
(PostFixedUpdate) Save position result with input id
(PostFixedUpdate) Send input to server
The problem is when I compare the server snapshot to the client position result and, if the results are different, want to instantly redo all inputs from that result. Like this...
(Update) Get input from user
(Update) Get snapshot from server
(FixedUpdate) Get last processed input id N from snapshot
(FixedUpdate) Get saved position result for input id N
(FixedUpdate) If saved position result is different from snapshot result: reposition user object to snapshot result and run step 6 - 8 to reapply all inputs since input with input id N.
(FixedUpdate) Apply input to user object
(Internal) Simulate physics
(PostFixedUpdate) Save position result with input id
(PostFixedUpdate) Send input to server
As you can see I have no control over the physics simulation (Step 7) which means I would have to apply all previous inputs before the physics simulation. This would ruin everything because I would not be able to save the position result for every reapplied input and I could also not guarantee that the result will always be the same. Because say you're walking up a staircase and apply FORWARD inputs several times in a row without running physics you might end up inside the staircase...
I'm not sure what to do... Is it possible to force a physics step? Any other ideas?
Answer by corewise · Jan 18, 2016 at 04:28 PM
I think I might have the answer to my own question. I thought it is best to share it in case anyone ends up in here looking for an answer as well. Since I'm not planning on using any physics beyond "player <-> player" and "player <-> static world/objects" I can simply use a CharacterController since its Move function will run collision checks on its own outside the physics simulation.
for this. I'm also using CharacterController's $$anonymous$$ove for rewind/replay clientside prediction. It's also useful on the serverside for keeping players in their own time stream. Downside is that you can't use Unity's rigidbody physics for networked objects since your CharacterControllers don't play nice.
The search is still on for a technique to allow a rigidbody controller with clientside prediction...
Your answer
Follow this Question
Related Questions
Changing rooms and spawning players with Multiplayer Example 2 Answers
Multiplayer problem: How can i figure out client lag in position updating calculated by the host? 0 Answers
MLAPI physics network sync problem 0 Answers
Best way to sync rigidbodies realtime? 1 Answer
Networking physics with HLAPI 1 Answer