Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
3  
Possible duplicate of gamedev.stackexchange.com/questions/20289/… If that doesn't answer your question: What have you tried? Where do you run into problems? –  Eric Jun 19 '12 at 9:05
    
@Eric true, I didn't find that particular answer by googling/searching. Thank you. I already started a close vote on this question with a link to your link. –  daemonfire300 Jun 19 '12 at 9:32
    
-1 This is a very broad question. Braid's timeshift is very different to a killcam: you're asking about slow motion, (possible) time-reversal, and replays and not being clear at all about which one you actually want. –  Jonathan Hobbs Jun 20 '12 at 0:52
1  
@JonathanHobbs you downvote something I already voted to close and said that is a duplicate? I am very sorry but this seems a bit overreacted to me. –  daemonfire300 Jun 20 '12 at 13:16

1 Answer 1

up vote 3 down vote accepted

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 y:

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 t1 (impact) to 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.

share|improve this answer
    
I would like to add that especially floating point operations are problematic since the outcome can be slightly different on another platform and these errors accumulate. –  Roy T. Jun 19 '12 at 9:50
    
@RoyT. What do you mean by another platform in context of braid or killcam? –  Kikaimaru Jun 19 '12 at 9:55
    
@Kikaimaru I think he means different hard/software platforms. For example, if you were to use CUDA for your own physics simulation, you would be restricted in both accuracy and rounding modes available. This could result in slight errors, or big ones, if your results propagate into the next simulation step and accumulate over time. –  melak47 Jun 19 '12 at 10:46
    
@melak47 even worse floating point operations differ per compiler version and setting, see gafferongames.com/networking-for-game-programmers/… –  Roy T. Jun 19 '12 at 12:15
    
@RoyT. that's just brilliant :/ –  melak47 Jun 19 '12 at 12:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.