Rewinding physics time?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
vendetta
Posts: 18
Joined: Sat Dec 31, 2011 7:49 pm

Rewinding physics time?

Post by vendetta »

Is it possible to rewind the physics system, for one specific entity in particular?

I'm attempting to implement Gaffer on Game's series on networked physics, and part of it relies on replaying / rewinding when a prediction error has occurred.

If it's not implemented, is there something similar I could do to achieve the same end result as rewinding?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rewinding physics time?

Post by Norbo »

Is it possible to rewind the physics system, for one specific entity in particular?
Not automatically, no.
If it's not implemented, is there something similar I could do to achieve the same end result as rewinding?
Keeping a cache of previous states would do the trick. You wouldn't necessarily need every single frame, but tracking the state every tenth of a second or however often would be good. This allows you to look back in time- at least for any object you've monitored.

Replaying isn't very workable for every object in a large dynamic simulation. Replaying the whole simulation would be prohibitively expensive, so you'd have to fake replaying individual parts- and that won't end up being quite right. For complex physics simulations I'd recommend using a different networking model.
vendetta
Posts: 18
Joined: Sat Dec 31, 2011 7:49 pm

Re: Rewinding physics time?

Post by vendetta »

Hi Norbo,

It would only be for one player (the local player). Although depending on how I do it, other dynamic shapes may need to be moved during the correction, but these shapes themselves won't be corrected.

Basically I'm trying to implement what this paragraph explains:

"When the client receives a correction it looks through the saved move buffer to compare its physics state at that time with the corrected physics state sent from the server. If the two physics states differ above some threshold then the client rewinds to the corrected physics state and time and replays the stored moves starting from the corrected state in the past, the result being the corrected physics state at the current time on the client:"

If I store my position at specific times, and find a prediction error, what would be the easiest way of going from the time of that prediction error and recalculating the position of my character up until the present time?

I've thought about rewinding all entities, ie setting all entities at their position / velocity etc... of the specific time, then calling the scene's update with the delta time until I reach my current time again.
Would that be too intense to do? Or is there a better way that I can mimic the updating of my entity to correct it to the right spot?

Or could I manually update only my entity, while not updating the rest of the space? I would have to set the position of all other dynamic objects while doing it (the position being a stored position at the time of the error), but they would then return to their original position. Is there a way to do this? (My local entity is a capsule)

Thanks for the help,
Mike
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Rewinding physics time?

Post by Norbo »

If I store my position at specific times, and find a prediction error, what would be the easiest way of going from the time of that prediction error and recalculating the position of my character up until the present time?

I've thought about rewinding all entities, ie setting all entities at their position / velocity etc... of the specific time, then calling the scene's update with the delta time until I reach my current time again.
Would that be too intense to do? Or is there a better way that I can mimic the updating of my entity to correct it to the right spot?
The easiest way (developmentally and conceptually) is indeed to pull the entire simulation back and resimulate from that point. For any nontrivial simulation, this isn't really practical. If it is some characters in a static environment it works well enough.

Updating a single entity is possible, but it's more difficult. The engine is built around the idea that things interact physically and coherently. Single-object updating throws that out of the window, so there's going to be hackiness involved. It would likely require taking over for the narrow phase, generating pairs as the object moves and checking them for collision. The solver also will have to be approximated- you could look at the contacts and figure out some movement to obey them. However, if only the character is updating, then presumably we treat the rest of the simulation as static. This will not be the same movement as if the simulation was actually updated.

Overall, I can't really recommend going down this road with anything beyond TF2 levels of interactivity. As he says later in that same article:
This leads me to an interesting point. The evolution of networked physics games is from first person shooters where characters run around in a static world while shooting each other, towards a dynamic world where players interact with the surroundings and each other. Given this trend I am willing to make the following bold prediction: traditional client side prediction as presented in this article, may soon be obsolete.
Lately, my preference is for stronger client authority. This makes personal motion a lot simpler- you get smooth movement for free, since the local player is authoritative over himself. Obviously this opens the door for cheating, but this is less of an issue than it might seem to be at first glance. There's a bit of security through obscurity (indie games probably aren't targeted as often as COD 19), and there are plenty of heuristics you can run serverside to help stop bad behavior.

For example- World of Warcraft clients have authority over character position. That's part of why there's so many teleport-based hacks. They still manage to autoflag/ban many of those hacks, though. A game with only ~32 players can afford to spend a lot more time checking players for good behavior than an MMO server, too, so it should more reliably catch cheaters.
vendetta
Posts: 18
Joined: Sat Dec 31, 2011 7:49 pm

Re: Rewinding physics time?

Post by vendetta »

My levels won't be overly complicated, and the terrain / buildings are all static physics props (same type of levels as TF2 basically)

Also, lol at COD 19.

You bring up an interesting point with WoW, I suppose as long as the server side checks to make sure the player made a valid move (IE they didn't just teleport 5000 units when they could only go 100 max), cheating could be kept to a minimum.

Thanks for the help on the subject, for now I'll just rewind the entire physics space and see how well that works.
Post Reply