GML Visual How do I flip a sprite based on player position?

I have an enemy in my game that follows the player. How would I be able to make the enemy sprite flip depending on if the player is to the left or right of the enemy so that the enemy is facing the player. I am not worried about up and down just left and right. I am using dnd in GMS2.

Thanks!
 
E

Edwin

Guest
It should work. Ask me if you have a questions.
EDIT: I don't know how to do it with DnD but It's not hard to do it with GML, so:
Code:
// PLAYER STEP EVENT
var dir = point_direction(x,y,enemy.x,enemy.y); // set your enemy object's name instead of "enemy".

if (dir > 90 && dir < 270) {
    image_xscale = -1; // flip image to the left
} else {
    image_xscale = 1; // flip image to the right
}
 
Last edited:
It should work. Ask me if you have a questions.
EDIT: I don't know how to do it with DnD but It's not hard to do it with GML, so:
Code:
// PLAYER STEP EVENT
var dir = point_direction(x,y,enemy.x,enemy.y); // set your enemy object's name instead of "enemy".

if (dir > 90 && dir < 270) {
    image_xscale = -1; // flip image to the left
} else {
    image_xscale = 1; // flip image to the right
}
I am confused on why you put this in the player code when it is for the enemy sprite. Is it supposed to be in the player code or the enemy code?
 
Not on my PC so I can't checkwhat I use exactly, but it is something along the lines of
Code:
image_xscale = sign(x - obj_player.x);
If that's facing the wrong way I just swap the x and obj_player.x around.
 
Top