• 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 Making Enemy Follow Player if it's in their Field of View

O

OttoMagao

Guest
So I want obj_enemy to follow obj_player (If it can see it with no walls inbetween) avoiding obj_walls. This is what I have as a code:

On the obj_control create event:
global.grid=mp_grid_create(0,0,room_width/32,room_height/32,32,32);

On the obj_enemy create event:
global.path=path_add();

On the obj_enemy step event:
with (obj_smoke) {
if ( !collision_line(x, y, obj_player.x, obj_player.y, obj_walls, 1, 0) and distance_to_object(obj_player < 2048) ) {

//Chasing
global.chasing = true;
global.path=path_add()
mp_grid_path(global.grid,global.path,x,y,obj_player.x,obj_player.y,false)
mp_grid_add_instances(global.path,obj_walls,true)
path_start(global.path,10,0,1)
show_debug_message("Player found");



}
}


With that the obj_enemy is not moving at all. With the show_debug_message I found that it is detecting the player, but it isn't following it. Thanks :D
 
Last edited by a moderator:
Top