Hello,
I’m developing a project in which the main mechanic is when the player picks up an object, a copy of the itself will show up and copy its last 10 seconds of movement. I already have the movement being copied, but it is the whole movement since start, not the last 10 seconds. How can I accomplish this?
public bool isCopying;
[SerializeField] Transform copy;
List<Vector2> positions;
[SerializeField] [Range(0f, 10f)] float recordTime;
void Start()
{
positions = new List<Vector2>();
}
private void FixedUpdate()
{
if (isCopying)
{
Copy();
}
else
{
RecordPosition();
}
}
private void RecordPosition()
{
if (positions.Count > Mathf.Round(recordTime / Time.fixedDeltaTime))
{
positions.Remove(transform.position);
}
positions.Add(transform.position);
}
private void Copy()
{
if (positions.Count > 0)
{
copy.position = positions[0];
positions.RemoveAt(0);
}
else
{
isCopying = false;
}
}
Here’s a gif of what I have:
https://media.giphy.com/media/finuyiZZ7EVuRXLfEm/giphy.gif