Fangames > Programming Questions
How to make the enemy's xscale change in order to be facing the player?
(1/1)
l3agu32:
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.
128-Up:
--- Code: ---if (player.x > enemy.x){
image_xscale = -1
} else {
image_xscale = 1}
--- End code ---
L4Vo5:
In one line of code:
--- Code: ---image_xscale = sign(sign(enemy.x-player.x)+0.1)
--- End code ---
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.
Navigation
[0] Message Index
Go to full version