I’m working on a game that has a Braid-like mechanic where the player can reverse time to any previous event that happened. I’m trying to figure out the best way to do this.
The simplest solution is to store a snapshot of each objects’s state each timestep, and then upon rewind pop those states. The giant unavoidable drawback here is that this uses a massive amount of memory if you’re supporting infinite playback, not to mention potential object allocations for state representations. This is definitely not how Braid does it since you can play a level for several hours or more.
A more difficult solution that works for an infinite length of time is by passing in a delta to each update (usual variable timestep behavior) and simply making the delta negative in the case of time reversal. That works great for a lot of stuff but leaves certain large holes.
For example, a character who is up on a ledge might be walking, and then falls off and walks at ground level. When passing in a negative delta, he will walk backwards as expected. However when he reaches the point that he hit the ground, he has no way of knowing that he was ever in the air, so will keep walking backwards on the ground and never return to the ledge.
It seems like in this case you need to perhaps store the Y velocity in a giant array and timestamps where it changes, then pop them off as you reach those stamps. This is the same as storing the state, though, and although it avoids a lot of the overhead it still can get huge. If the main character goes up and down ledges for 1 hour that needs to be supported. I can make a couple gigantic float arrays without more than like 100k pf overhead, but that’s still a lot.
So what would you guys do? The state/delta combo will probably work but a system that eventually breaks seems really dirty to me.