Answer the question
In order to leave comments, you need to log in
How to record character movements in unity2D?
Hello, I would like to record the player's movement, and then, for example, create a clone in the next round and reproduce the movements recorded in the first round on it. I do not really understand how to implement the recording and playback of movements. Thanks in advance for your reply)
Answer the question
In order to leave comments, you need to log in
The most naive option is to make a queue of Transform and write each change in the player's position to this queue. Then when you need to play the action, we extract the elements and pass them to your movement function. This option is thrown offhand and has a number of disadvantages, one of them is the consumed memory for storing all positions. It can be improved by the fact that we will save the key positions of the player, and generate intermediate data based on where we are going from, where we are going and how. An example of key positions: the character started walking, then started running, finished running, starting the jump, peak position of the jump, landing.
Transform player;
Queue<Transform> positions;
private void Start()
{
player = GetComponent<Transform>();
positions = new Queue<Transform>();
}
private void Update()
{
Move()
}
private void Move()
{
// move
positions.Enqueue(player.transform);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question