Hi,
I’m running in little trouble here. I try to create a little puzzle game based on physics and cloning.
The thing I want to do is to be able to replay the action of any object based on the user input. To be a little more specific, I have a character that move around a map using the default (but tweaked) 3rd person controller. Then when the player triggered a specific script, the game instantiate a clone of my character and give the control to the user. Then, The firsts characters (because this can be repeated over and over) has to redo what the user did before.
So far I’ve isolated the input into a new class (I’m coding just with c#) and save them into a dictionary (sort of hash map). The key is the frame number and the value is an object representing input for this particular frame. Then when I have to replay the “action of the user” I simulated input for each frame with the corresponding one that was saved in the dictionary. As you can expect I have reset the position and the rotation of the character at each beginning of the redo.
That technique works but is far from being perfect. The longer I run the simulation the more precision I lost. For example, if I move around in a 30m diameter circle for 1 minute, I get an error of about 1m on the final position. This can be problematic for my game, as I need position to trigger scripts for my game. Moreover, even a very small lost of precision can be very bad. I experienced this, when I walked on a edge and when I replayed the “simulation” the “clone” fell of the edge because he was only 10cm further.
About the code (I can post every lines of it if you want) I used FixedUpdate() everywhere and use FixedDeltaTime for the math.
Do I miss something or Is Unity (physics and character controller) unable to get the same result on the same hardware based on the input ?
Thanks in Advance,