schteppe / cannon.js

A lightweight 3D physics engine written in JavaScript.
http://schteppe.github.com/cannon.js
MIT License
4.69k stars 712 forks source link

Question: rewind or step only some bodies #85

Closed benjajaja closed 11 years ago

benjajaja commented 11 years ago

My clients receive server updates with network delay. I should then compensate stepping the world for the amount of delay. But updates do not affect all bodies - so I must either rewind the entire world, update affected bodies, then fast forward again, or be able to step only the bodies affected by updates.

I tried calling world.step with a negative amount, but it seems like collisions are not accounted: http://jsfiddle.net/gipsyking/J9Y7B/3/

So, how could I only step some bodies? Should I remove the other bodies temporarily? Should I maybe create another world object only for these "update" calculations? Is there maybe a flag I can set? Am I completely off-track?

You library is great, thanks in advance!

benjajaja commented 11 years ago

Pardon me, I have come to realize that this question is out of scope for cannon.js.

https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking explains lag compensation for bullets, which are instant rays and not real physics objects.

schteppe commented 11 years ago

You are correct. And yes, Cannon.js does not step backwards in time. You can manually step some of the bodies forward using their current velocities (x += v*dt), but then you would get simulation stability problems. Letting the world step all of its bodies forward in time and adding some compensation is probably the way to do it.

Thanks for using the lib, and good luck with your implementation!