Let’s learn how paths work in GameMaker. With their help, you can set the trajectory along which the object will move.


A path is created just like any other entity in GameMaker. In the Asset Browser, right-click and select Create->Path.


I will call it pth_enemy and in the window that appears, you can draw a path. It is preferable to start from the point 0, 0. And then by pressing the left mouse button, we indicate the points along which the object will move


There are also several important options in this window. The first one is Closed, if it is pressed, the last point will be connected to the first


Another option is Smooth Curved. If you specify it, the path lines will be rounded


Object movement

Now that we have a path, we can tell the object to move along it. To do this, you need to create an object and add a sprite to it. For the object, add the Create event and start a movement in it using the path_start method, which accepts 4 arguments. The first is the name of the path along which to move, the second is the speed, and the third is what to do when the path ends (start again, go back in the opposite direction, continue or stop). And the last one is where to start the movement, from the coordinate point relative to the room (the coordinate from which we started drawing the path will be used) or relative to the object.

path_start(pth_enemy, 5, path_action_continue, 0)

I place the object in the room and start the game and my object moves. The movement starts from the place where we placed the object because I specified 0 as the last parameter. If I set it as 1, then the movement will start from the zero point in the room.