dimforge / nphysics

2 and 3-dimensional rigid body physics engine for Rust.
https://nphysics.org
Apache License 2.0
1.63k stars 122 forks source link

Add the ability to take snapshots of the physical world. #83

Open sebcrozet opened 7 years ago

sebcrozet commented 7 years ago

See the related thread on the forum.

janhohenheim commented 6 years ago

Has there been any progress on this?
It would be quintessential for multiplayer online games.

Ralith commented 6 years ago

For most game purposes, exact reproducibility isn't important (especially if you're receiving authoritative updates from a server at high frequency), so you can just synchronize position and velocity by hand.

janhohenheim commented 6 years ago

I agree for the client, but lag compensation requires you to "scroll backwards" in time.

Ralith commented 6 years ago

Efficient lag compensation implementations usually don't involve snapshotting the entire world state at every frame, but just reconstructing sufficiently important parts of the past (e.g. player positions). They certainly don't need the ability to restart the simulation from a point in the past, let alone perfectly reproducibly.

seivan commented 5 years ago

Depends on what kind of roll back you're looking for. For Counter Strike, they just keep track of transforms and stuff like ammo/weapon/aim and use those for hit-scan rollbacks.

More complex games with different rules regarding who to "favour" will need to rollback much more. Take Overwatch that has projectiles, it will need to tackle a bit more than just hit-scan + transforms.

Although, there is nothing preventing you to store the values you deem important for a rollback, and re-simulate with said values seeded on demand it would be nice if this was builtin.

Ralith commented 5 years ago

I don't think restarting the entire simulation from the past is generally required or appropriate for hit detection, no matter how you're simulating your projectiles.

seivan commented 5 years ago

So what approach do you recommend? Also hit detection was just an example there’s much more to roll back for.

Ralith commented 5 years ago

Explicitly capturing whatever transforms you care about to whatever precision you care about and manually driving swept collision detection or ray-casting in the past is straightforward and more efficient than storing a complete reproducible state for every time step, let alone re-simulating the entire world from that point.

seivan commented 5 years ago

Not sure I follow...

If one would need to roll back to a frame (e.g N-30) and run a simulation with new context sent from a laggy client, how would that work with current features?