R
RetroRain
Guest
The problem I've been having, I have been unable to solve despite my best efforts. I have searched many tutorials, forum and Reddit posts, and YouTube videos, and I can't solve this problem that I am having.
The problem is this:
I have a maze. In the maze, are the walls obviously, a player, and an enemy. I want the enemy to follow the player, avoiding the walls. Even though diagonal movement has been disabled, the enemy keeps cutting corners despite that.
I realized that it cuts corners, because of this piece of code in the step event:
I found out, that you're not supposed to have this code in the step event, as it keeps restarting the path, and causes that cutting corners that I don't want.
Anyway, so how do I update the x and y final destination so that the enemy can follow the player around the maze when he moves?
Here are the code blocks for my objects:
objGrid
CREATE EVENT
objEnemy
CREATE EVENT
I tried putting this code in the CREATE even, and using alarms to delete the path, and re-create it right afterwards, and it throws the enemy object off the grid (snapped off the grid, and still follows the path and cuts corners)
I simply want to make it so my enemy follows the player wherever he goes on the maze, I just don't know the proper code on how to do it, despite various code syntax I have used. I have even used path_action_restart, and I just don't know what to do.
Any help would greatly be appreciated.
Thank you.
The problem is this:
I have a maze. In the maze, are the walls obviously, a player, and an enemy. I want the enemy to follow the player, avoiding the walls. Even though diagonal movement has been disabled, the enemy keeps cutting corners despite that.
I realized that it cuts corners, because of this piece of code in the step event:
Code:
if (mp_grid_path(global.grid,path,x,y,mx,my,false))
{
path_start(path,1,path_action_restart,false);
}
Anyway, so how do I update the x and y final destination so that the enemy can follow the player around the maze when he moves?
Here are the code blocks for my objects:
objGrid
CREATE EVENT
Code:
cellWidth = 16;
cellHeight = 16;
hcells = room_width div cellWidth;
vcells = room_height div cellHeight;
global.grid = mp_grid_create(0,0,hcells,vcells,cellWidth,cellHeight);
mp_grid_add_instances(global.grid,objWall,false);
CREATE EVENT
Code:
path = path_add();
mx = objPlayer.x;
my = objPlayer.y;
if (mp_grid_path(global.grid,path,x,y,mx,my,false))
{
path_start(path,1,path_action_restart,false);
}
I simply want to make it so my enemy follows the player wherever he goes on the maze, I just don't know the proper code on how to do it, despite various code syntax I have used. I have even used path_action_restart, and I just don't know what to do.
Any help would greatly be appreciated.
Thank you.