grazianobolla / godot4-multiplayer-template

Client/Server Authoritative Multiplayer Framework for the Godot4 Engine
MIT License
145 stars 13 forks source link

Replace TestMotion with MoveAndSlide #9

Open inFamousOne opened 3 days ago

inFamousOne commented 3 days ago

Replace TestMotion with MoveAndSlide Fixed various errors.

Fixes https://github.com/grazianobolla/godot4-multiplayer-template/issues/8

The propose solution is 2 parts

  1. "Inverting" the deviation check logic.
    • we now capture the clients state along side the input
    • using this we can now compare the incoming state with the captured state at the time of the tick
    • if a deviation is found we run the simulation starting from the incoming state using all inputs that haven't been processed
    • during simulation we also need to stop taking in new inputs on the client.
  2. using move and slide
    • move and slide assumes physics delta
    • so we have to do some clever math to cancel it out while applying process delta and then the inverse after the call.

The need for 1. is due to the fact that running the simulation using move and slide actually moves the player. so to prevent constant simulations we need to only do so when a deviation is found first. otherwise we would need a "ghost" characterbody3d that we would constantly be moving and checking against. and can become quite complicated when things like state machines are introduced.

grazianobolla commented 15 hours ago

Thank you so much! I will take a look at it this weekend !