How do I make a sprite flip depending on which direction the obj is moving

K

Knightly19

Guest
Im trying to code an rpg and I have ran into a small problem. I cant get the mob's sprites to flip left or right when following the player, currently they just face right. Also I want them to wander in a small area and need them their images to flip depending on which way they are moving.
 
A really simple way is to use a negative value for image_xscale.
A value of -1 will flip it horizontally, giving the impression of facing the opposite direction.
A common practice is to have your basic sprite facing right (the 0* direction in GM), and flip your sprite with image_xscale = -1; to make it face to the left.
You can also use this trick in isometric games, as "down" and "right" are the same flipped sprite, as are "up" and "left"
 
Last edited:
K

Knightly19

Guest
I can flip the sprite my problem is making it do it so that it faces the direction its moving. I don't know how to check which direction it moving.

A really simple way is to use a negative value for image_xscale.
A value of -1 will flip it horizontally, giving the impression of facing the opposite direction.
A common practice is to have your basic sprite facing right (the 0* direction in GM), and flip your sprite with image_xscale = -1; to make it face to the left.
You can also use this trick in isometric games, as "down" and "right" are the same flipped sprite, as are "up" and "left"

This is what Im using to make the enemy move.
move_towards_point(objPlayer.x, objPlayer.y, walkspeed);
if (distance_to_object(objPlayer) < awareradius)
{
walkspeed = 2
}
else
{
walkspeed = 0
}};
 
K

Knightly19

Guest
Something like this?
point_direction(x, y, objPlayer.x, objPlayer.y)
If You speak about left right direction You need to clamp values where 0 be right, 180 left and so on.
Thanks! this is what I needed.
 
Top