Need Help with flipping AI sprite

J

Justin Firestone

Guest
So I've been working on my first platform and am having issues making my sprite flip to the opposite direction when moving. The enemy is afraid of heights and it turns off that fear whenever the sprite flips here is the code. Any help would be greatly appreciated.

Create event -
image_speed = 0.2
dir = -1;
movespeed = 3;
grav = 0.2;
hsp =0
vsp = 0;
fearofheights = 0;

Step event -
hsp = dir * movespeed;
vsp += grav;

//Hoizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
x += hsp;

//Veritical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
if (fearofheights) && !position_meeting(x+(sprite_width/2)*dir, y+(sprite_height/2)+8, obj_wall)
{
dir *= -1;
}
}
y += vsp;

//Enemy Collision
if (place_meeting(x,y,obj_player))
{
if (obj_player.y < y-14)
{
with (obj_player) vsp = -jumpspeed;
repeat (250) instance_create(obj_enemy.x, obj_enemy.y, obj_blood);
instance_destroy()
}
else
{
repeat (250) instance_create(obj_player.x, obj_player.y, obj_blood);
with (obj_player)
{
instance_destroy();
}
scr_death()

lives -= 1;

}

}
 
P

Preston

Guest
You could use something like:

image_xscale in respect to the direction you are moving. If you set it to 1 it would be normal, and -1 would mirror it.

Make a if statement for which direction you are currently pointing/moving then put the above inside it.
 
Top