E
E.M.I
Guest
Hey there! I'm making a top-down adventure game with GMS2 and wanted to code a pathfinding system so the enemies in my game could avoid obstacles when chasing the player. However, the code doesn't seem to be working.
This is my code:
In my grid object's Create event:
In the enemy's Create event:
In the enemy's Step event:
What's weird is that, when I try drawing the path I'm creating with the draw_path function, the path appears correctly and changes when the player object moves. However, the enemy just doesn't want to move.
Also, when I replace the if statement in the second-to-last line to check if mp_grid_path was executed correctly, it works. So the problem is in path_start.
Thanks!
-Emi
This is my code:
In my grid object's Create event:
Code:
globalvar enemyGrid;
enemyGrid = mp_grid_create(0, 0, room_width/16, room_height/16, 16, 16);
In the enemy's Create event:
Code:
enemyPath = path_add();
Code:
mp_grid_path(enemyGrid, enemyPath, x, y, obj_eitim.x, obj_eitim.y, true);
path_start(enemyPath, 0.9, path_action_continue, true);
if (path_start(enemyPath, 0.9, path_action_continue, true))
show_debug_message("Working");
Also, when I replace the if statement in the second-to-last line to check if mp_grid_path was executed correctly, it works. So the problem is in path_start.
Thanks!
-Emi