Hey everyone! Hope you all had a fantastic jam. As we make our way through the play and rate phase, I've been getting asked how I made the ghost drivers (or replays) in Insect Racing League. Here's a breakdown of the key aspects.
Defining a run
First up I modeled the data that I would need to recreate a run. This ended up being an array of data points, where each point stored the race time, XYZ position, and the orientation as Euler angles in the X and Y axes (racers cannot change their orientation around Z axis).
I also stored some metadata such as the name of the player, the insect that they used, and their final time for the run.
Special note: I used the Newtonsoft.Json package because it handles arrays better than Unity's built-in JsonUtility.
Recording a run
During every run, this recorder script is saving the player's position and orientation at regular intervals. Once a run completes, that run data gets turned into a JSON string and saved to disk (if it's a new personal best) and submitted to the online database if it's a world record.

Playing it back
When you start a new run, that JSON string that represents your personal best and the world record are given to two separate ghost controllers, which use the current run time to interpolate between the positions and orientations in the data points.

And that's really about it! The code I removed for these images was mostly just the file reading and writing. Let me know if you have any further questions.