How to Make Objects Follow Others in GameMaker

TIME : 2016-01-08
How to Make Objects Follow Others in GameMaker

There are two main approaches in GameMaker, depending on the effect you want.

Chasing an Object

If you want an object to chase another, cutting corners and heading straight for it, use a Step event. Under the Move section, choose "step toward" and set:

  • x: the x position of the object you want to chase
  • y: the y position of the object you want to chase
  • speed: how fast you want it to move

Following an Exact Path

If you want the follower to trace the leader's positions precisely, create two 1D arrays (called "lists" in GML), one for x and one for y. Have the object defining the path push its values onto the top of each list, and have the follower pull from the bottom and then delete those entries.

GML may handle those last two steps together, but since I haven't used lists much, you may need to experiment a bit. Note that this method requires Advanced mode.