Time Mechanic


Today I implemented the time mechanic.

The mechanics function is to create a clone of the player each time the player presses the reset time button. The clone then performs the same movement and actions that the player did before pressing the reset button.

To make this happen, what I do is record the input from the player using a applies scripts that checks all registered input for each frame. if a registered input is pressed down during a frame, the time since the start of the loop is recorded. Once the button stops being pressed, a second time is recorded. These two recordings together with the information of the buttons are used to create a coroutine which is applied on the clone. The coroutine will set the input button press to true and then false in the clones input manager by reading the recorded timestamps.

The reason why I chose to use coroutines is because this makes the use of an update function in clones completely unnecessary, which allows the game to use a lot more clones than it would with an update functions on each clone.

 To wait the right amount of time before applying the input, the "WaitForSeconds" function is used.

In the end, I managed to make a lot of clones without slowing down at all, this will probably help immensely as we go forward in the project. Here is a short video displaying some clones (orange) jumping around in a scene, moving like the player (blue) used to.


Kommentarer

Populära inlägg i den här bloggen