Time Game 1 - Implementing Time Travel (Replay system)
This is my current progress of a time travel puzzle game created with Unity3D
I will briefly outline how I implemented time travel in Unity3d.
As the title suggests, this method will be the same if you are trying to create some sort of replay system.
The first thing we need to do is to record our players movement.
The easiest thing to do seems to be to record the players position and rotation (Transform).
For this we create an object which will be used to hold the recorded information.
public class RecordingData
We then need to call a method which records the data.
private RecordingData recordingData = new RecordingData();
We need to call the TakeSnapshot method at a known interval.
I have used coroutines to ensure a consistent sample of data.
In the below example we are using 0.05 seconds which is a rate of 20fps.
This seems to offer a smooth enough playback rate (discussed later in this article).
public bool DoRecording = true;
Then we just need to play this data back. Again this is done with a coroutine.
public bool DoPlayback = true;
This is the same as the recording loop except it calls Next SnapShot().
The NextSnapshot method simply retrieves the desired transform of the object.
private RecordingData.RecordData? _desiredMoveLocation = null;
We then move the object each update frame using the Lerp function (this helps keep the movement smooth).
public void Update()
There are many many ways of doing this. I am outlining how I did it.
I have simplified my implementation for the purposes of this post (to outline roughly how it was done).
Any feedback or improvements are welcome :)
Feel free to ask me anything (I have overlooked some internal workings in this post).
I also have a Unity3d Forum WIP post for this game prototype (in progress):
I have not gone into any detail on how the replay data can be saved and loaded between games (I have implemented this in my prototype).
I can try and write a post outlining this if this is of interest?