E
eldinhelja
Guest
Hello, I have made a platform game and added AI who finds path and then follow the target in this case Player.
I made that player can fly, If I fly then Enemy spawns at the "spawner location" and from there he starts following me, BUT if I stop flying, basically if I collide with Grass Enemy instantly disappears and teleports to that corner.
-I tried various methods of PathFinding but always same.
With one method, when I stop (collide with something), enemies wouldnt teleport to the top corner, instead they would just stop in one place and again, If I start to fly (not colliding with anything) they would start following me again.
Code of AI pathfinder :
That is it all.
My player step event :
I made that player can fly, If I fly then Enemy spawns at the "spawner location" and from there he starts following me, BUT if I stop flying, basically if I collide with Grass Enemy instantly disappears and teleports to that corner.
-I tried various methods of PathFinding but always same.
With one method, when I stop (collide with something), enemies wouldnt teleport to the top corner, instead they would just stop in one place and again, If I start to fly (not colliding with anything) they would start following me again.
Code of AI pathfinder :
Code:
//END STEP EVENT
grid=mp_grid_create(0,0,room_width/32, room_height/32, 32,32);
path = path_add();
mp_grid_add_instances(path, obj_SolidParent, true);
mp_grid_path(grid,path,x,y,obj_Amila.x,obj_Amila.y,1);
path_start(path,3,path_action_stop, true);
My player step event :
Code:
var rkey;
rkey=keyboard_check(vk_right);
var lkey;
lkey=-keyboard_check(vk_left);
var jkey;
jkey=keyboard_check(vk_up);
move=rkey+lkey
hsp=move*movespeed
if(!keyboard_check(vk_space)){
if (vsp<10) vsp+=grav
if(place_meeting(x,y+1,obj_SolidParent) || place_meeting(x,y+1,obj_WALL)) {
vsp = jkey*(-jumpspeed)
}
}
//Horizontal Collision
if(place_meeting(x+hsp,y,obj_SolidParent) || place_meeting(x+hsp,y,obj_WALL) ){
while(!place_meeting(x+sign(hsp),y,obj_SolidParent) && !place_meeting(x+hsp,y,obj_WALL)) {
x+=sign(hsp);
}
hsp=0;
}
//Vertical Collision
if(keyboard_check(vk_space)==false){
if(place_meeting(x,y+vsp,obj_SolidParent) || place_meeting(x,y+vsp,obj_WALL)){
while(!place_meeting(x,y+sign(vsp),obj_SolidParent) && !place_meeting(x,y+sign(vsp),obj_WALL)) {
y+=sign(vsp);
}
vcol=true;
vsp=0;
} else{
vcol=false;
}
}
x+=hsp;
y+=vsp