- Home /
Updating Rigidbody position more than once in FixedUpdate
Hey guys ! I'm working on a multiplayer game where physics is preponderant and I need to use a Rigidbody-based character controller but I'm having a little problem during server reconciliation.
To summarize : the player rigidbody on the client-side may diverge from its position on the server. When the difference is too big the client takes the player rigidbody back to the last known server position and reapplies many inputs at once in one FixedUpdate. My problem is how to apply these inputs !
1) Setting transform.position is not working since it does not consider physics and ignore all collisions.
2) Rigidbody.MovePosition is not working either because it resolves only once by FixedUpdate.
Any idea on how to do this ? Any insight is welcome ! Thanks <3
Never$$anonymous$$d. It seems Unity built-in solutions are not meant for networked physics. I got some good insight on this thread link text which match what I've been thinking.
I guess I will try implementing custom physics and come back here to share if this works.
Answer by Drayanlia · Mar 04, 2021 at 08:14 AM
Looks like I've been quite hasty posting all of this !
Physics can be simulated more than once by frame by disabling Physics auto-simulation in the project settings and then manually calling Physics.Simulate(Time.fixedDeltaTime).
I will run some more tests but so far it looks like it does what I wanted. Using this one can even work with force or velocity and ignore position.
Answer by $$anonymous$$ · Mar 04, 2021 at 01:07 AM
Try using a while loop in the FixedUpdate method
This is not working with rigidbodies for the reasons I mentionned in the first message. I had this working with the non physics CharacterController though because its Move method resolves instantly and can be used more than once in one frame. Physics can only be simulated once by frame if my understanding is good.