r/howdidtheycodeit • u/Mooco2 • Jul 10 '25
Simulating Results in a Racing Game?
In a lot of racing games, once the player completes a race, the game can essentially complete the rest of the race for the remaining racers "off-camera" instantly and provide detailed results for the player to browse, including lap times, replays, and top speeds that may not have been achieved yet during regular gameplay (and sometimes even DNF'ing by wrecking).
What's the standard practice for how this would be achieved?
16
Upvotes
11
u/Isogash Jul 10 '25
I don't know any games that do quite what you describe, but if they provide working replays then probably the game just continued to simulate in the background once you'd already finished.
One way to fake ending times pretty would be to take the most recent time difference between each car on the track at the last checkpoint they passed, then take the last car to genuinely finished and just add the time difference on for each car in turn.
4
u/Deive_Ex Jul 10 '25
I also don't really know any game that does this, specially the replay part, but in many game engines you can manually step the physics engine, which allows you to simulate many physics frames in a single render frame (of course, this usually means blocking the thread until the simulation is done), which is probably the part that really matters. Idk how long it would take to simulate an entire race in a game like Mario Kart, but this would probably allow you to record the CPU positions/inputs in order to create a replay.
4
u/Blue_Link13 Jul 12 '25
A way to do it is to just to make the simulation go faster. After all you might need the game to run at human speeds, but the game AI can play a race as fast as the CPU can run it once you are done.
Then if you keep a record of stuff like the position data of the cars over time, you can make it so the graphics engine grabs that data to render you a replay of the race.