me as very unexperienced game developer, I wondered how I could achieve something like re-winding the time in my game or jump back to a special moment (killcam) and replay it for the user.
The only way you can achieve this is if your game is completely deterministic. In mathematical terms, that means that if you have the function:
y = x^2
Then you can always get a value for
x if you have a value for
x = square_root(y)
For every time
t, you must be able to generate a world state. If you have something like a bullet being fired from a gun, then you want to be able to rewind its position from impact back to when it left the barrel. There are two ways to achieve this:
Record the position of the bullet every x frames. When replaying, interpolate between those frame positions.
Have a function for bullet position that takes a time
t. Have this function be completely deterministic and rewind it from
t0(departure). This is called integration in mathematics.
Now, this second method is obviously the best, but it's also the hardest. Because in a game, not everything can be broken down to functions:
- Players mash on keys and move with mouses.
- Networking delays can mean physics run at a different framerate.
- Some functions can not be integrated (see: N-body problem).
Most likely you'll end up with a combination of the two: integration for bullet position and interpolated recordings for player positions.