enemy ai chasing problem

C

crazybloodmonkey

Guest
so i'm making a 2d shooter and i tried to program it to make my enemies chase the player, while i technically got it working they don't exactly follow the player the just go all over the play the float up they go through the ground they do chase me but as i said some of them start to float up and stuff so yeah anyone know how to fix this i'm guessing because there no path finding or something i don't know i keep seeing people saying that in the comments of this video. so anyways any help would be appreciated

i watched this tutorial and i did everything he did( i know i should use tuts as reference not really copying pasting them but i'm in a rush)


but to save you the time here is what i coded ,in my starting room i put the creation code
enum e_state
{
idle,
chase
}

then i made two events in obj_e( which is the bad guy)
create event:
state = e_state.idle;
vsp = 0;
hsp = 0;

step event :
switch (state)
{
case e_state.idle:
{
hsp = 0;
vsp = (min (7,vsp+0.05));
if (distance_to_object(obj_player) < 96) state = e_state.chase;
}
break;
case e_state.chase:
{
dir = sign(obj_player.x - x);
hsp = dir * 2;
vsp = (min (7,vsp+0.05));
if (distance_to_object(onj_player) > 128) state = e_state.idle;
}
break;
}

// Horizontal Collision
if (place_meeting(round(x+hsp),round(y),obj_floor))
{
while(!place_meeting(round(x+sign(hsp)),round(y),obj_floor)) x += sign(hsp);
hsp = 0;
}
x += hsp;

// Vertical Collision
if (place_meeting(round(x),round(y+vsp),obj_floor))
{
while(!place_meeting(round(x),round(y+sign(vsp)),obj_floor)) y += sign(vsp);
vsp = 0;
}
y += hsp;
 
C

crazybloodmonkey

Guest
lol thanks, it always seems like it's the little things that cause my problems. now i need to make the object change to the running sprite but that's is a problem for another day, but thank you guys for the help
 
Top