To get the cars to follow the circuit, I mapped the circuits to several points. And using the
move_towards_point function I make everything happen correctly.
In addition, I use two objects: object 1 / pink square => to be followed by the cars, object 2 \ green square => to reset the car collision with object 1 (so that the collision with object 1 only happens once).
Sometimes I have to make an adjustment in the position of object 2, because it has to be in the path between two objects 1, otherwise it will not clear the collision.
I thought there would be another solution considering that I've seen in video tutorials a platform games function (usually used on villains so they do not fall into the void).
If I am not mistaken, it is as if at any moment the object throws a particle, and if it did not reach anything until a certain moment or height (y), the object would turn around and run in the opposite direction.
I imagine there is a function similar to this to use in my case. So that you detect the circuit object and do not let the car get out of it.
It's hard enough to have to put up points, then move the position of each of them to the code (I had to do this, because I preferred to create only one object and keep repeating it all over the circuit, I could have created several. Ex => point 1, point 2, ...).
Not wanting to plagiarize, but an example of what I want for my game, is this game:
Video of game: https://www.youtube.com/watch?v=knZRQZI25Fo