How to create time control in a game

Hi, I am making a 'blinx the time sweeper' type game where you control time. I want it to be like this. You press J and you rewind. You press K and you fast forward. You press J+K to pause time. (FF is the only one that affects you.) I only have one problem: I have absolutely no Idea how to do it. Any Suggestions?

Note:I am a total noob at scripting, so some scripting help would be much appreciated.

This should get you started: http://unity3d.com/support/documentation/ScriptReference/Time-timeScale.html

When you understand that, you’ll have a much better grasp of what to do. Note: you’ll want to learn some scripting to understand what’s on that page.

Heres a script that will assist you in rewinding position, only rewind…

private var Movements = new Array();
private var MovementIndex : int = 0;
private var rewinding : boolean;

function Update ()
{
	if(!rewinding)
	{
		Movements.Add(transform.position);
		MovementIndex++;
	}
	
	if(MovementIndex > Movements.Count - 1)
	{
		MovementIndex = Movements.Count;
	}
	
	if(Input.GetKey("e"))
	{
		rewinding = true;
		Rewind();
	}else
	{
		rewinding = false;
	}
}

function Rewind ()
{
	MovementIndex--;
	transform.position = Movements[MovementIndex];
	Movements.RemoveAt(MovementIndex);
}

Let me explain,

This script basically stores the position vectors every frame, and then rewinds them at the push of “e” key. It just iterates through the positions backwards, hope this helps

P.S This is in Javascript, C# is a bit different, but mostly the same.

Epitome Games

I know this is an old thread, but I’ve made a plugin that would directly answer this question, if you’re still interested:

Chronos - Time Control on the Asset Store

It can handle fast-forward, slow, pause, rewind, on any object individually and on any built-in or custom property.

If you want to do it yourself, you won’t have a choice but to learn some scripting. And unfortunately, it’s not an easy problem.

If all your objects are moving at the same time, using Time.timeScale will take care of accelerating, slowing or pausing. If you need rewind, you’ll have to save snapshots of the game objects’ properties at regular intervals (e.g. in a List) and interpolate between them. If your objects don’t all follow time at the same pace, try making each of them use its own component with a custom “timeScale”, that you would multiply with “Time.deltaTime” in update.

in rewind maybe you reverse velocities of everything and the collisions should symmetrically undo what happened before
also, for enemy ai, have a list of actions and for every action there’s a undo action, then just execute the undo list, which will be in reversed order to the normal list. also see at which point you should start

If you wanna only slow your game or make it faster you can use SlowMooo asset. it’s very cheap and working with every part of game even sounds. It also will be upgraded soon for mobile. It very easy to use, just add script to your character.