Legacy GM enemy faceing at player

phillipPbor

Member
how do you make enemy flip sprite at the player?

enemy look left when player is on left horizontal.
enemy look right when player is on right horizontal.

is there a tutorial some where?

upload_2017-2-13_14-46-33.png
 

jo-thijs

Member
Put this in the step or end step event of the enemy object:
Code:
if obj_player.x != x
    image_xscale = sign(obj_player.x - x);
and make sure the x origin of the sprite of the enemy is centered.

You could alternatively also use this if you have separate sprites for facing right and left:
Code:
if obj_player.x < x
    sprite_index = spr_enemy_left;
else if obj_player.x > x
    sprite_index = spr_enemy_right;
 

phillipPbor

Member
Put this in the step or end step event of the enemy object:
Code:
if obj_player.x != x
    image_xscale = sign(obj_player.x - x);
and make sure the x origin of the sprite of the enemy is centered.

You could alternatively also use this if you have separate sprites for facing right and left:
Code:
if obj_player.x < x
    sprite_index = spr_enemy_left;
else if obj_player.x > x
    sprite_index = spr_enemy_right;
thanks. still if boss will face player then it will go to direction where the boss faced.
 

jo-thijs

Member
thanks. still if boss will face player then it will go to direction where the boss faced.
You mean you also want to change movement towards where the enemy or boss faces?
Then do this:
Code:
if obj_player.x != x
    image_xscale = sign(obj_player.x - x);
hspeed = image_xscale * 4;
or this:
Code:
if obj_player.x < x {
    sprite_index = spr_enemy_left;
    hspeed = -4;
} else if obj_player.x > x {
    sprite_index = spr_enemy_right;
    hspeed = 4;
}
and change 4 to whatever speed the enemy/boss should have.
 

phillipPbor

Member
You mean you also want to change movement towards where the enemy or boss faces?
Then do this:
Code:
if obj_player.x != x
    image_xscale = sign(obj_player.x - x);
hspeed = image_xscale * 4;
or this:
Code:
if obj_player.x < x {
    sprite_index = spr_enemy_left;
    hspeed = -4;
} else if obj_player.x > x {
    sprite_index = spr_enemy_right;
    hspeed = 4;
}
and change 4 to whatever speed the enemy/boss should have.

this topbot boss is speciel it can slowly increace hsp 0.1 each and if the player dodge that attack, then a top will turn by decreacing the hsp while facing the other way at the player
 

jo-thijs

Member
So, like this?
Code:
if obj_player.x != x
    image_xscale = sign(obj_player.x - x);
hspeed = clamp(hspeed + image_xscale * 0.1, -4, 4);
I'm not entirely sure what you mean.
 

phillipPbor

Member
Ok, the picture makes it clear, but the code I gave should do that already.
What goes wrong?

welp junebug you must look at this vid for example. its so cool

using the of from yours gaving to me.

see how this diamond moves like a swing or a gyro? that's the example
 
Last edited:

phillipPbor

Member
well I figured it out when your away then found some

the sprite suppost to face the player

Code:
//turn...............................................................

hspeed = image_xscale;

if cam_player.x < x {
    spd = -0.1;
} else if cam_player.x > x {
    spd = 0.1;
}
 

jo-thijs

Member
well I figured it out when your away then found some

the sprite suppost to face the player

Code:
//turn...............................................................

hspeed = image_xscale;

if cam_player.x < x {
    spd = -0.1;
} else if cam_player.x > x {
    spd = 0.1;
}
So, is the issue solved?
 
Top