Ghost Replay For Racing Game

Hello, I have been struggling for awhile now to get my racing replay system to work. I have finally got it storing the positions and rotations to playback, however when I play back the ghost while testing it is too fast. I want to make it go the same speed as the original car but I can not figure out how to do it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
    public float movementSpeed, rotationSpeed;
    public float fbInput, lrInput;

    public List<PointInTime> ghostPointsInTime;

    public bool isReplaying;
    public GameObject ghostCar;

    private float nextActionTime = 0.0f;
    public float period = 0.5f;

    void Start()
    {
        movementSpeed = 8.0f;
        rotationSpeed = 100.0f;
        ghostPointsInTime = new List<PointInTime>();
        ghostCar = GameObject.FindGameObjectWithTag("Ghost");
    }

    void Update()
    {
        fbInput = Input.GetAxis("Vertical");
        lrInput = Input.GetAxis("Horizontal");
        Move();

        if (Input.GetKeyDown(KeyCode.Return))
            StartReplay();
        if (Input.GetKeyUp(KeyCode.Return))
            StopReplay();
    }

    public void FixedUpdate()
    {
        if (isReplaying) 
            Replay();          
        else
            RecordMovement();
    }

    public void Move()
    {
        transform.Translate(Vector3.forward * Time.deltaTime * movementSpeed * fbInput);
        transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed * lrInput);
       
    }

    public void RecordMovement()
    {
        if (Time.time > nextActionTime)
        {
            nextActionTime = Time.time + period;
            ghostPointsInTime.Add(new PointInTime(transform.position, transform.rotation));
            Debug.Log("Recording");
        }
    }

    public void Replay()
    {
        if (ghostPointsInTime.Count > 0)
        {
            PointInTime pointInTime = ghostPointsInTime[0];
            ghostCar.transform.position = pointInTime.position;
            Debug.Log(pointInTime.position);
            ghostCar.transform.rotation = pointInTime.rotation;
            Debug.Log(pointInTime.rotation);
            ghostPointsInTime.RemoveAt(0);
        }

        else
        {
            StopReplay();
        }

    }

    public void StartReplay()
    {
        isReplaying = true;
    }

    public void StopReplay()
    {
        isReplaying = false;
    }
}

Time.time is actually the time since the game booted. I think that’s your problem.

You can use Time.timeSinceLevelLoad instead but I highly recommend you track your own notion of playback time in a floating point variable, then advance it each frame yourself with :

myTime += Time.deltaTime;

You probably want to do the same thing time-wise (starting from zero) when you record and when you playback.

Full reference on Unity Time here:

Thank you for the response, I will try that out and take a look through the documentation