KPJ
Member
Hi everyone! I need help. I want the enemy to move toward the player if the player shoots within a certain range. At first, all my code was working and the enemy moved toward the player but then all of a sudden it stopped working and the enemy didn't move.
Anyone know what's happening? Thanks!
Code:
//if player shoots
with (oEnemy)
{
if (distance_to_object(oPlayer) < bulletalertrange)
{
placeofinterestx = oPlayer.x;
placeofinteresty = oPlayer.y;
estate = estates.chasealert;
}
}
//Enemy create
grid = mp_grid_create(0, 0, room_width/32, room_height/32, 32, 32);
mp_grid_add_instances(grid, oSolid, false);
path = path_add();
//Enemy step
if (estate == estates.chasealert)
{
ChaseAlert();
}
//Enemy chase alert script
nearestdoor = instance_nearest(x, y, oDoor);
mp_grid_path(grid, path, x, y, placeofinterestx, placeofinteresty, true);
path_start(path, enemyspd, path_action_stop, true);
if (x == placeofinterestx) && (y == placeofinteresty)
{
if (alarm[2] == -1)
{
alarm[2] = 5;
}
}
if (distance_to_object(nearestdoor) < 20)
{
with (nearestdoor)
{
if (closing)
{
opening = true;
closing = false;
}
}
}