Rewind?

Let’s say I happen to have a character, and I decide to walk around with him… I shoot a few lasers, and kick a soccer ball. Then, I press a button, and the lasers come back to life, reenter my gun, and both my character, and the soccer ball go back to their original status - All of this happening over time, as if hitting the rewind button on a dvd.

When I release the button, everything goes back to normal operation, and I am free to do something ELSE. For instance, if I am rewinding, and let go of the button while lasers are reentering my gun, the lasers start going away form the gun again. However, if I wait until they are in the gun, and gone, they never re-appear unless I fire some again. I imagine this would be possible, because as I rewind, rigidbody velocities are rewinded as well. Form there, they don’t actually “fast forward”, they simply continue normal operation with that velocity.

If I leave the scene “paused” after rewinding, I could potentially fast forward too, but if I don’t leave it paused, the current status would become “Present”, and fast forwarding would be impossible.

So! How would you go about doing this?

I’d stick to caching values such as the player’s position and whatnot into an array every frame or something, though only allow them to go back in time so far as you don’t want the array sizes to get hectic.

From there, simply backtrack each event with what you’ve stored in the array.

Grr, I was hoping I wouldn’t have to do that…

Do I have any other options?

you have to store the data yourself, unfortunately there is no Rewind() function. unity is a nice engine, but you still need to do some of the more uncommon stuff yourself.

maybe you can think of a better way than storing positions for every object in the scene for every frame. just as an example you could store something like “walked forward for 2 seconds without doing anything else, shot 2 times but kept walking, and so on …”. this doesn’t work for every kind of game obviously (my mouse ALWAYS moves when i play 1st-person shooters for example), but i’m sure you can find a clever solution.

Thanks for the advice. I’ll see what I can come up with!

Not sure if you’ve worked on this any, but I was bored so decided to.

private var position;
private var rotation;
private var cur_frame;
private var rewound : boolean;

private var updateInterval = 1.0;
private var accum = 0.0; 
private var frames = 0; 
private var timeleft : float; 
private var fps = 15.0; 
private var lastSample : double;

function Start()
{
	position = new Array();
	rotation = new Array();
}

function Update () 
{
	var i;

	if(!Input.GetMouseButton(2))
	{	
		// Put your character movement code here
	
		var newSample = Time.realtimeSinceStartup;
		var deltaTime = newSample - lastSample;
		
		++frames;
		lastSample = newSample;

		timeleft -= deltaTime;
		accum += 1.0 / deltaTime;
		
		if( timeleft <= 0.0 )
		{
			fps = accum / frames;
			timeleft = updateInterval;
			
			accum = 0.0;
			frames = 0;    
		}

		if(rewound)
		{
			position.Clear();
			rotation.Clear();
		}

		if(!(position.length <= Mathf.Round(fps + 0.5) * 10))
		{
			position.RemoveAt(0);
			
			for(i = 0; i < position.length - 2; ++i)
				position[i] = position[i + 1];
		}

		if(!(rotation.length <= Mathf.Round(fps + 0.5) * 10))
		{
			rotation.RemoveAt(0);
			
			for(i = 0; i < rotation.length - 2; ++i)
				rotation[i] = rotation[i + 1];
		}
	
		position.Push(transform.position);
		rotation.Push(transform.rotation);
		
		cur_frame = position.length - 1;
		rewound = false;
	}
	else
		if(cur_frame > 0)
		{
			transform.position = position[cur_frame];
			transform.rotation = rotation[cur_frame];
			
			--cur_frame;
			rewound = true;
		}
}

Note: read and do what the comment says for everything to work properly.

It doesn’t support animation, but it ought be easy with what I give you.

Edit: you also need to be holding the middle mouse button for it to work.

Another edit: I’ve only applied this to a single node, so you’ll have to put a bit of effort into it for everything else to rewind as well.

Edit on top of the other two edits: added rotation. High five.

Thank you man, I was looking for something like that !