Ok, could someone help me? I am making a new platformer game but I wan't it to have a twist, the main character has the ability to "travel back in time" like in the game Dusk 2 If this is in the wrong forum I will delete it and post it in the correct one thanks :D! Please help however you can!

At 5/23/12 02:53 PM, SketchistGames wrote:
Ok, could someone help me? I am making a new platformer game but I wan't it to have a twist, the main character has the ability to "travel back in time" like in the game Dusk 2 If this is in the wrong forum I will delete it and post it in the correct one thanks :D! Please help however you can!

I've actually thought about this before (i've never implemented it, was just thinking for fun) - but i've never solved it.
I'll think aloud here (just some things that come to mind), and see if any of this helps.

Think of time as a variable
use arrays to store the last movement data? (Ie ran left for x seconds, right for x seconds, jumped...) - use the time variable to control how far back it goes

At 5/23/12 02:53 PM, SketchistGames wrote:
Ok, could someone help me? I am making a new platformer game but I wan't it to have a twist, the main character has the ability to "travel back in time" like in the game Dusk 2 If this is in the wrong forum I will delete it and post it in the correct one thanks :D! Please help however you can!

I've actually thought about this before (i've never implemented it, was just thinking for fun) - but i've never solved it.
I'll think aloud here (just some things that come to mind), and see if any of this helps.

Think of time as a variable
use arrays to store the last movement data? (Ie ran left for x seconds, right for x seconds, jumped...) - use the time variable to control how far back it goes

that's all i'm able to come up with at the moment

thought about it some more. I can get more specific on my theory

you can do this one of two ways:

one: create one array for movement. You could constantly record the player's position (every quarter or half-second) and reverse those steps be moving backward through that array, clearing each variable it passes. The reason you clear them as you pass them is if the player wants a "drop-off point" somewhere in the middle of that array, then you still have the start of the array as a buffer in case they want to go back again.

or two (this is the one I like): create one array for movement and one array for time. Each time the player presses a key, record the key and the time started. When the player releases the key record the end time. This will decrease the size of the array and speed up your program (as compared to the first method, which is constantly checking. This method only "checks" when something happens) - then use logic to run back through the steps, same as method one. The reason for the time array (if it isn't obvious) is because the timer isn't a constant. It's an unknown.

I finally decided to get off my lazy ass and throw something together quickly.
Here's a few warnings: This is not proper programming. It looks like crap - it works. If you want to use it, you'll have to do some clean-up.
I'm not sure how "buggy" it is. It hasn't been stress-tested. It gets the "character" to around 8 or so pixels from where they were supposed to be at that point (at 30 FPS)

From what I gathered from his post, he wants us to give him a plot twist for his platformer where the main character can travel back in time.

So maybe after he has traveled back in time, he finds out he was never born and that his mother is really his father and that insects have taken over the world because he stepped on a ladybug when traveling back in time and that gave the nazis a technology advantage in the world war two which they used to make experiments on bugs who then turned like godzilla and half of the world is now a desert wasteland where water is very rare so it costs like a lot of silver which is now the main resource of the world because you can make drinking cups out of silver which only the humans can use because the insects don't have thumbs on their hands.

At 5/23/12 05:33 PM, ProfessorFlash wrote:
From what I gathered from his post, he wants us to give him a plot twist for his platformer where the main character can travel back in time.

So maybe after he has traveled back in time, he finds out he was never born and that his mother is really his father and that insects have taken over the world because he stepped on a ladybug when traveling back in time and that gave the nazis a technology advantage in the world war two which they used to make experiments on bugs who then turned like godzilla and half of the world is now a desert wasteland where water is very rare so it costs like a lot of silver which is now the main resource of the world because you can make drinking cups out of silver which only the humans can use because the insects don't have thumbs on their hands.

haha, that's pretty interesting. Anyway, I thought it was obvious what he was asking - especially after I played some of the game that he linked to.

Side-note: I probably should have used a positional array rather than a directional array. Would be much more accurate, and possibly faster.
ie. at the moment it uses directions and time to get to its new destination. Instead, I could simply use one array with a position. That would only work for "walking", though. For jumping, special effects, etc it would be better to use the Key.isDown approach

At 5/23/12 07:28 PM, Sandremss128 wrote:
that game just makes cheap snapshots of the current position and velocity of the player and has an option to revert it; the environment stays the same (those moving platforms were unaffected).

If you truly want to have a good time thing you need to either:

1. make A LOT of snapshots
2. store the user input and calculate time steps back from it.

The second method is more deterministic than the first one because you can invert your position determining functions and get the actual position of the previous time step.

I used the second method, though it's very basic - though there may be a third option (branching from the second a bit)
Again, I used time as not only a variable but a major determining factor of the "backward time" script. If you remove that (aside from the "pauses" in which the player does nothing) you can just store points in the array and use the game's logic to get from point a to point b - though that's a bit more complex, as you will have to basically create an AI and in the case of jumping, increase the effect of gravity on the player (i'm thinking about jumping onto a platform. It would look weird if the character just jumped backwards)

All the complexities aside, after everything's done it would probably be a small amount faster than described in method two, though honestly not enough to warrant that big of a headache. I'd just go with the user input method.

I used the second method, though it's very basic - though there may be a third option (branching from the second a bit)
Again, I used time as not only a variable but a major determining factor of the "backward time" script. If you remove that (aside from the "pauses" in which the player does nothing) you can just store points in the array and use the game's logic to get from point a to point b - though that's a bit more complex, as you will have to basically create an AI and in the case of jumping, increase the effect of gravity on the player (i'm thinking about jumping onto a platform. It would look weird if the character just jumped backwards)

All the complexities aside, after everything's done it would probably be a small amount faster than described in method two, though honestly not enough to warrant that big of a headache. I'd just go with the user input method.

Ah, a fourth option appears! egg82 uses the master ball!

how about combining them? Yes, you'd end up with another array, but here's the upside:
at the moment the key/time is not perfect. In fact, if you move around for 20 seconds you end up way off from the starting position. The time/space isn't quite right either. It leaves a gaping hole for AI to fill (which is a pain in the arse by itself)
but if you did a ket/space/time combo, it would remove all adverse effects. Use the script posted above, but add the space points to it and check the x and y axis for collision (math only, please), then stop and get a new point when the collision is true. In theory, it would be perfect. You wouldn't even need an AI.

Surely you would just need to take note of the players position periodically - such as every half a second. "Velocity" doesn't need to be noted because if it's already programmed into the players movement then just taking note of positions would be enough.