- Home /
Best way to record/save race car runs
So, I have a racing game mostly done. Now I want to be able to record the car's run so that I can play it back. I'm NOT trying to record video, or the screen, or the game, I want to record the car (GameObject) so that when the next racer races, they can race against the previous run. So it will be a completely new game, but a bot racer (computer controlled gameobject) will replicate the previous or best run.
What's the best way to do this? Record the position and rotation with AnimationCurves, then read those curves and set the position/rotation later? Create a custom asset that stores the position and rotation and then uses them to set the bot's later? Wouldn't that be a lot of data if captured each frame? Maybe just store rotation and speed, and let it replay those to establish position?
Maybe there's an asset out there that can do this, but most of what I saw were scene based, or didn't save. I just want to track the car's position and rotation, and use that data later. Suggestions?
Answer by FortisVenaliter · Oct 09, 2015 at 02:44 PM
There are generally two ways of doing this...
The first is to store position and rotation for every frame. At the end of the race (or if the amount of data exceeds some threshold), you then process that data into a series of curves which can be saved with a much smaller footprint.
The second is to store input. Store when it accelerates, decelerates, and turns. That will have a much smaller footprint initially, but if it's not perfect, any error can get exponentially worse very quickly.
Right. I figured on storing input, but I don't trust it. So it boils down to finding the best way to store the rotation and position for the car. I'm thinking I don't need every frame, but maybe every other, third, or even 10th frame; whatever won't look jagged on playback.
Yeah, that's what I was saying about boiling it down. Store it every frame, but then reduce that to splines that only have a frame or two a second, but look good regardless.
Just save the transform.position/rotation to a List. Set the routine to only do this every x distance from last point to make the data consistent or do it by time period to Automatically give a sense of speed.
Right, that's what we're discussing. Storing the transform's position and rotation every half second or so, but then using splines to interpolate the spaces in between. $$anonymous$$ore ore less keyfra$$anonymous$$g the animation. I was just wondering if there were built in methods for keyfra$$anonymous$$g, and storing them, or if I was going to be forced to write my own, like the ListOf that you mentioned. Since all I need is the position and rotation, I'd probably make my own class that only stored those two items, so I could make a ListOf();