Skye
Skye

Reputation: 15

How to make a object follow another object around walls game maker language

So, i want an object to follow another one. But if the player object gets to far ahead the other one gets stuck behind a wall. So if you go round a corner and the following object gets trapped because it cant follow you since its trying to move towards the player. Which cause it to get stuck against a wall. The code i currently have for it is:

"Create Event"

path = path_add();

"Step Event"

mp_potential_path_object(path, obj_unit_1.x, obj_unit_1.y, 1, 4, obj_border);
path_start(path, 1, 0, 0);

If anyone has already posted about this please mention, thanks

Upvotes: 1

Views: 3386

Answers (1)

Henry Hsu
Henry Hsu

Reputation: 76

Without knowing additional details for how your project/objects are laid out, I am going to offer just general idea type solutions.

1) On collision with the wall object, you can try to find the edge of the wall object using the sprite's size and add that as a point to move towards. (assuming the wall's aren't tiled and there's another wall there)

2) You can make a backup path of the player's movement, and have the following object follow that path. Assuming the path the player took is still clear and able to be moved through, any path the player moved through should be valid for the following object as well.

3) Not sure if it's in keeping with the mechanics of your game, but some game (like in diablo 3) if your follower/pets gets too far behind the player, they just auto teleport next to the player's location.

Upvotes: 1

Related Questions