• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM The Enemy Ai will not stop when I tell it to.

Rivo

7014
I'm using the built in A* algorithm to make the enemy follow the player

The enemy is currently in attack mode, and I want him to shoot from a distance. So I have created a little radius that the enemy has to stop on so it doesn't get to close, or else there will be no 'shooting from distance' lol

Here is the code.
Code:
if !distance_to_object(oPlayer) <= radius{
    if mp_grid_path(pathfinder_grid, path, x, y, oPlayer.x, oPlayer.y, true){
        path_start(path, spd, path_action_stop, false);
    }
}
The enemy just keeps following the player and I don't really understand why. Any solutions? Any help at all would great thanks.
 

jo-thijs

Member
This:
!distance_to_object(oPlayer) <= radius

is equivalent to this:
(!distance_to_object(oPlayer)) <= radius

Assuming the enemy is always at a distance more than 1 pixel from the player,
that is equivalent to:
1 <= radius

which, if your radius is at least 1 pixel, is equivalent to:
true

Use > and get rid of the !.

You'll also need to manually end the path if the enemy gets too close.
 
Top