P
Pedau666
Guest
I have a problem when enemy chases player. When the player is on the ladder, so when he is above the enemy the enemy constantly changes its direction and tries to follow the player which causes enemys sprite to make horrible things on the screen. Do you have any ideas how to repair this?
EDIT: Enemys sprite also breaks up when it is trying to catch the player when he is behind the wall which enemy cant go through because he is constantly walking into the wall and then going to the another side and then again chasing player.
enemy step event
enemy create event
EDIT: Enemys sprite also breaks up when it is trying to catch the player when he is behind the wall which enemy cant go through because he is constantly walking into the wall and then going to the another side and then again chasing player.
enemy step event
Code:
if global.pause = 0
{
vsp = vsp + grv;
hsp = dir* walksp;
if instance_exists(o_player) && distance_to_object(o_player)<200 &&distance_to_object(o_player)>0{
dir = sign(o_player.x-x)
}
//horizontal collision
if(place_meeting(x+hsp,y,o_solid))
{
while(!place_meeting(x+sign(hsp),y,o_solid))
{
x = x + sign(hsp);
}
hsp = 0;
dir *= -1;
}
x = x + hsp;
//vertical collision
if(place_meeting(x,y+vsp,o_solid))
{
while(!place_meeting(x,y+sign(vsp),o_solid))
{
y += sign(vsp);
}
vsp=0;
if (fearofheights) && !position_meeting(x+(hit_box_w/2)*dir, y +(hit_box_h/2)+8, o_solid)
{
dir*=-1;
}
}
y = y + vsp;
//horizontal collision enemy_wall
if(place_meeting(x+hsp,y,o_enemy_wall))
{
while(!place_meeting(x+sign(hsp),y,o_enemy_wall))
{
x = x + sign(hsp);
}
hsp = 0;
dir *= -1;
}
//vertical collision enemy_wall
if(place_meeting(x,y+vsp,o_enemy_wall))
{
while(!place_meeting(x,y+sign(vsp),o_enemy_wall))
{
y += sign(vsp);
}
vsp=0;
if (fearofheights) && !position_meeting(x+(hit_box_w/2)*dir, y +(hit_box_h/2)+8, o_enemy_wall)
{
dir*=-1;
}
}
//animation
if(!place_meeting(x,y+1,o_solid))
{
sprite_index = walk;
image_speed = 1;
}
else
{
image_speed = 1;
if(hsp==0)
{
sprite_index = stay;
}
else
{
sprite_index = walk;
}
}
//animation enemy_wall
if(!place_meeting(x,y+1,o_enemy_wall))
{
sprite_index = walk;
image_speed = 1;
}
else
{
image_speed = 1;
if(hsp==0)
{
sprite_index = stay;
}
else
{
sprite_index = walk;
}
}
if(hsp != 0) image_xscale = sign(hsp);
};
Code:
//fearofheights
fearofheights = 1;
//walk
walksp = 1.5;
grv = 1;
//health
hp = 40;
//sprites
hit_box_h = 64;
hit_box_w = 20;
walk = s_enemy4;
stay = s_enemy4;
//shoot
can_shoot = 0;
shoot_time = 0;
dmg = 1;
//points
pnt = 10;
flash = 0;
vsp = 0;
hsp = walksp;
dir = 1;