Record and replay movement
Hey! Im trying to save the movement of the Player's transform. Then i want to be able to "replay" this movement. What i have at the moment:
public List<Vector3> savedPositions;
public List<Vector3> recordingPositions;
public Vector3 lastFramePosition;
public void Record()
{
Vector3 posDifference = playerTransform.position - lastFramePosition;
recordingPositions.Add(posDifference);
}
public void PlayRecording()
{
if (savedPositions == null || savedPositions.Count <= 0)
{
isPlaying = false;
player.characterMovement.useGravity = true;
}
else
{
isPlaying = true;
player.characterMovement.useGravity = false;
if (isReverse)
{
playerTransform.position -= savedPositions[savedPositions.Count - 1];
savedPositions.RemoveAt(savedPositions.Count - 1);
}
else
{
playerTransform.position += savedPositions[0];
savedPositions.RemoveAt(0);
}
}
}
This works fine for replaying the changes of the transforms position, but for the mechanic im trying to build, i need this replayed movement to be relative to the cameras direction. If i record going forward with the Player i want to go forward(relative to the current Cameras forward direction) whenever i replay it.
What am i missing?
Greetings from Germany :-) And thanks in advance.
Comment