M
Monster25
Guest
I've been using pathfinding for a while now in my game (top down shooter). The enemies are supposed to have 2 different states whenever they are not engaged, idle and roam. While in idle they stay still and while they are roaming they pick a random direction and move there until an alarm makes them pick again between idle and roam just to make them act a bit more natural. I've succesfuly implemented the pathfinding using motion planning for when the enemies chase you or when they are startled and look for you in your last position but for some reason when I try to use the same code but calculate the end coordinates for the roaming path they won't budge at all.
This is the code found in their roaming state:
scr_enemy_movement();
//Pathfinding
var cx = (lengthdir_x(1,enemy_angle)/32)*32+16;
var cy = (lengthdir_y(1,enemy_angle)/32)*32+16;
if (mp_grid_path(global.grid,path,x,y,cx,cy,1))
{
path_start(path, movespeed,path_action_stop, false);
}
the enemy movement script calculates their movespeed and for some reason if I try and use lengthdir_x and lengthdir_y to calculate the end of their path they won't move at all but if I place the player's coordinates or any other hard coordinate instead, they will move accordingly and correctly.
I'm not sure what's happening and why this is not working, is the pathfinding not able to use lengthdir calculations?
This is the code found in their roaming state:
scr_enemy_movement();
//Pathfinding
var cx = (lengthdir_x(1,enemy_angle)/32)*32+16;
var cy = (lengthdir_y(1,enemy_angle)/32)*32+16;
if (mp_grid_path(global.grid,path,x,y,cx,cy,1))
{
path_start(path, movespeed,path_action_stop, false);
}
the enemy movement script calculates their movespeed and for some reason if I try and use lengthdir_x and lengthdir_y to calculate the end of their path they won't move at all but if I place the player's coordinates or any other hard coordinate instead, they will move accordingly and correctly.
I'm not sure what's happening and why this is not working, is the pathfinding not able to use lengthdir calculations?