Godot Version
4.5
Question
In a racing game, all vehicles are on the specific path in the racing track, and the game is usually implemented to display which player is positioned first, second and so on.
The simplest naive implementation I could think of is deploying multiple Area3Ds on the whole track, perhaps every few short distances. Whoever touches the Area3D first becomes the 1st position, and so on. But then this won’t be real-time reflection and we will only got updates when players touch the Area3Ds. If the game is very fast, the players won’t noticed the “lag” in updates.
Another way that makes more sense is to compare the 3D position of each vehicle to the current travelling length of the track. But I believe this will need some mathematics that isn’t just a simple distance formula. You probably need to create some sort of a perpendicular line on the track and find the nearest distance to a point of this line for each player. But if the track branches out in multiple paths, then this also needs to be managed too…
We have racing games since forever and those retro consoles could do this. With a single CPU only running in a few MHz back then, this should rather be very simple to calculate. What is the secret sauce here?
Does Godot have any built-in function to check for this or how do we do this in Godot?