# Simplest way to make a car follow a route

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

• Usually those voids are detected with place_free, throwing particles seems tricky for this purpose. Could you use a path for the circuit? – Juanpa Dec 28 '18 at 1:20
• @Juanpa What do you mean by using a path to the circuit? – Boneco Sinforoso Dec 28 '18 at 21:10
• A game maker resource called "Path" – Juanpa Dec 28 '18 at 21:52
• @Juanpa It worked, it turns out that I can not get each car to start in a different position (like on a starting grid) without having to mark with false the absolute option. – Boneco Sinforoso Dec 29 '18 at 0:05
• I got it! Just add a value to the variable path_position. The value of the variable is defined as a percentage of the path length. See: docs.yoyogames.com/source/dadiospice/002_reference/paths/… – Boneco Sinforoso Dec 29 '18 at 0:36

## 1 Answer

Through the comment from site member Juanpa, I got a simpler way of doing what I wanted at first.

The GameMaker has a feature called path.

By clicking on the path, you can choose a room as the background (the room is already with the circuit drawing, so I can draw the path above the circuit drawing):

You click at any point to start the path:

After setting the starting position of the maze, the next point will be the next location of the path to be followed (see that with 3 or more points the path closes, this is because the closed option is selected):

Path completed:

Below is a link that will help you use some of the important features of this feature:

https://docs.yoyogames.com/source/dadiospice/001_advanced%20use/004_paths.html