How to make a replay system for a game

This idea comes from Clone Armies. Basically when the player dies, a new player is created with the past player replaying the actions you played in that iteration.I googled it and I asked mistrals codestral ai and it told me this:
Me: i want to make a game that when the player dies all the actions he performed before he died gets saved and a clone of it is created

Mistral: Creating a game that saves the player’s actions and creates a clone of the player’s previous state when the player dies is a complex task that involves several different areas of game development. Here are some possible approaches to consider:

  1. Action Recording: Record the player’s actions as they occur, such as the player’s movement, input, and game state. This can be done using a combination of scripting and data structures to store the player’s actions in a format that can be easily replayed or cloned.
  2. Checkpointing: Save the player’s progress at certain points in the game, such as at the end of each level or at certain milestones. When the player dies, the game can be reloaded from the most recent checkpoint, allowing the player to continue from where they left off.
  3. State Cloning: Create a clone of the player’s game state when the player dies, allowing the player to continue playing as a new character with the same abilities and equipment as the previous character. This can be done using serialization to save the player’s game state to a file, and then deserializing the game state to create a new clone of the player character.
  4. Replay System: Implement a replay system that allows the player to watch a recording of their previous actions, such as a slow-motion replay or a cinematic camera that follows the player’s movements. This can be used to show the player what they did wrong or to allow them to learn from their mistakes.

Implementing these features will require a combination of scripting, data structures, and game design. It may also be helpful to consult resources such as game development tutorials, forums, and documentation to learn more about the specific techniques and technologies that are used to implement these features.

Me: I want it to be action Recording

Mistral: Action recording is a technique that involves recording the player’s actions as they occur, such as the player’s movement, input, and game state, and then storing the recorded actions in a format that can be easily replayed or cloned.

Here are some possible approaches to implementing action recording in a game:

  1. Input Recording: Record the player’s input as they play the game, such as the player’s movement, jumping, and shooting. This can be done using a combination of scripting and data structures to store the player’s input in a format that can be easily replayed.
  2. Game State Recording: Record the game state as it changes, such as the position and velocity of all game objects, the state of all game systems, and any other relevant game data. This can be done using serialization to save the game state to a file, and then deserializing the game state to replay the recorded actions.
  3. Replay System: Implement a replay system that allows the player to watch a recording of their previous actions, such as a slow-motion replay or a cinematic camera that follows the player’s movements. This can be used to show the player what they did wrong or to allow them to learn from their mistakes.
  4. Clone System: Implement a clone system that allows the player to create a clone of their previous state, such as a new character that has the same abilities and equipment as the previous character. This can be done using the recorded actions and game state to create a new clone of the player character.

Implementing action recording will require a combination of scripting, data structures, and game design. It may also be helpful to consult resources such as game development tutorials, forums, and documentation to learn more about the specific techniques and technologies that are used to implement these features.

Here’s an example of how you might implement input recording in a game using scripting and data structures:

  1. Create a data structure to store the player’s input, such as a list or array of input events.
  2. In the game loop, record the player’s input as it occurs, such as the player’s movement, jumping, and shooting.
  3. Store the recorded input events in the data structure.
  4. When the player dies, use the recorded input events to replay the player’s actions, such as by rewinding the game state to the beginning of the recording and then playing back the recorded input events.

Here’s an example of what the input recording code might look like:

using UnityEngine;
using System.Collections.Generic;

public class InputRecorder : MonoBehaviour
{
    private List<InputEvent> inputEvents = new List<InputEvent>();

    void Update()
    {
        // Record the player's input
        if (Input.GetButtonDown("Jump"))
        {
            inputEvents.Add(new InputEvent(InputEventType.Jump));
        }
        if (Input.GetButtonDown("Fire1"))
        {
            inputEvents.Add(new InputEvent(InputEventType.Shoot));
        }
        if (Input.GetAxis("Horizontal") != 0)
        {
            inputEvents.Add(new InputEvent(InputEventType.Move, Input.GetAxis("Horizontal")));
        }
    }

    public void ReplayInput()
    {
        // Rewind the game state to the beginning of the recording
        // ...

        // Play back the recorded input events
        foreach (InputEvent inputEvent in inputEvents)
        {
            switch (inputEvent.Type)
            {
                case InputEventType.Jump:
                    // Simulate the player jumping
                    // ...
                    break;
                case InputEventType.Shoot:
                    // Simulate the player shooting
                    // ...
                    break;
                case InputEventType.Move:
                    // Simulate the player moving
                    // ...
                    break;
            }
        }
    }
}

public enum InputEventType
{
    Jump,
    Shoot,
    Move
}

public struct InputEvent
{
    public InputEventType Type;
    public float Value;

    public InputEvent(InputEventType type, float value = 0)
    {
        Type = type;
        Value = value;
    }
}

I would stay away from AI if this is your current level programming-wise. AI is just going to confuse and confound your learning efforts. Seriously.

Instead, just work at your problems one tiny step at a time: that’s how it’s gonna work with or without AI, so why not leave out AI?

If you can’t get it from online tutorials, then you won’t get it from this little text box.

Imphenzia: How Did I Learn To Make Games:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Thank you but i am really excited for this game and i really want to get it done and this is the only part that i am confused on and i am pretty sure there are no tutorials on it. Also is this an advanced or intermediate question?
also after watching the video I might as well ask the ai what the code its showing me does step by step as id rather be lazy and not google documentation and just ask pros but that was just foolishness on my part.

There are many tutorials. This is an extremely common mechanic in racing games.

Google for “unity ghost replay” or “unity ghost player”

Don’t forget the two steps to doing tutorials:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Thank you for guiding me in the right direction.

You are correct that there is much I don’t understand in the video but I hope to slowly tweak it step by step to hopefully eventually learn it.