- Home /
Why can't I see how I rewind time?
Hi, in my game you can rewind time an other stuffs. I have that an effect plays when I am rewinding. When I play the game it works, but when I build it and click the buton to rewind. You cannot see how it rewind, but when you stop pressing the button, the player teleports to the last position. This only happends in the mechanics that plays a shader. This is my code.
PointTime:
using UnityEngine;
public class PointTime { public Vector3 position; public Quaternion rotation;
public PointTime (Vector3 _position, Quaternion _rotation)
{
position = _position;
rotation = _rotation;
}
}
TimeBod:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TimeBod : MonoBehaviour { public bool isRewinding = false;
public Health health;
List<PointTime> pointsInTime;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
pointsInTime = new List<PointTime>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
StartRewind();
}
if (Input.GetKeyUp(KeyCode.Mouse1))
{
StopRewind();
}
}
void FixedUpdate()
{
if (isRewinding)
{
Rewind();
}
else
{
Record();
}
}
void Rewind()
{
if (pointsInTime.Count > 0)
{
PointTime pointTime = pointsInTime[0];
transform.position = pointTime.position;
transform.rotation = pointTime.rotation;
pointsInTime.RemoveAt(0);
health.RewindDamage(0.4f);
}
else
{
StopRewind();
}
}
void Record()
{
pointsInTime.Insert(0, new PointTime(transform.position, transform.rotation));
}
public void StartRewind()
{
isRewinding = true;
rb.isKinematic = true;
}
public void StopRewind()
{
isRewinding = false;
rb.isKinematic = false;
}
}
Perhaps fixed update is running multiple times during an update. The default is 50 fixed update calls per second, but this is not spread out evenly over the second. With a low frame rate the FixedUpdate will be called multiple times between Update calls. Since Update is called once per frame, what is rendered might not represent what is actually taking place if FixedUpdate is changing the position of the said object multiple times between renders.