I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: l3agu32 on May 10, 2016, 08:37:49 AM

Title: How to make the enemy's xscale change in order to be facing the player?
Post by: l3agu32 on May 10, 2016, 08:37:49 AM
I want the enemy's xscale to change when the player changes his side. For instance, if the enemy's x position is 400 and the player's x position is less than 400, the enemy should be facing the left. Thank you.
Title: Re: How to make the enemy's xscale change in order to be facing the player?
Post by: 128-Up on May 10, 2016, 09:25:15 AM
Code: [Select]
if (player.x > enemy.x){
    image_xscale = -1
} else {
    image_xscale = 1}
Title: Re: How to make the enemy's xscale change in order to be facing the player?
Post by: L4Vo5 on May 10, 2016, 05:53:27 PM
In one line of code:
Code: [Select]
image_xscale = sign(sign(enemy.x-player.x)+0.1)enemy.x can be replaced with x if the instance calling is the enemy. And player.x can be replaced with x if the instance calling is the player.