1

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

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Skye
  • 15
  • 1
  • 6

1 Answers1

1

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.

Henry Hsu
  • 76
  • 1
  • 3
  • I like your 2nd idea. However, i have no clue how to implement it. This is because i cant find a way to make the player object save a path for the enemy to follow :/ – Skye Jan 25 '18 at 08:33
  • For path related documentations https://docs.yoyogames.com/source/dadiospice/002_reference/paths/changing%20paths/index.html you can use path_add to to create a new path, path_add_point() to add new points to the path, and path_assign to copy the player backup path to a new path for the follower if needed. Alternatively, I was thinking another approach can be to add invisible path finding "node" objects in these problem areas, and if the following object gets stuck, they can instead take a path to these objects, then follow a path stored at these "nodes" to walk through a clear path? – Henry Hsu Jan 27 '18 at 00:32