Author Topic: How to make the enemy's xscale change in order to be facing the player?  (Read 1239 times)

l3agu32

  • Wannabe
  • Posts: 22
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Chrome 50.0.2661.94 Chrome 50.0.2661.94
    • View Profile
  • Playstyle: Keyboard
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

  • Spike Dodger
  • Posts: 114
  • Lives are an antiquated concept.
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Chrome 50.0.2661.94 Chrome 50.0.2661.94
    • View Profile
  • Playstyle: Keyboard
Code: [Select]
if (player.x > enemy.x){
    image_xscale = -1
} else {
    image_xscale = 1}

L4Vo5

  • Cherry Eater
  • Posts: 59
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 50.0.2661.94 Chrome 50.0.2661.94
    • View Profile
  • Playstyle: Keyboard
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.
I have to admit, i still haven't beaten IWBTG