How can i pin number

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ktotoetoia

I am creating a 2D platformer in which there is an enemy that has to change its side when it touches the platform, but using scale it changes its side every frame, how can I pin number(-1)?

Please add some code.

clemens.tolboom | 2021-04-23 15:36

If globals.player.position.x < position.x
  Vel.x = speed
  Scale.x =-1
If globals.player.position.x > position.x
  Vel.x =  -speed
  Scale.x = 1

Ktotoetoia | 2021-04-23 15:45

:bust_in_silhouette: Reply From: clemens.tolboom

You have to add the current direction to both if. Maybe swap Vel.x < and Vel.x > between the ifs.

# Moving to the left
If Vel.x < 0 and globals.player.position.x < position.x
    Vel.x = speed
    Scale.x =-1

# Moving to the right
If Vel.x > 0 and globals.player.position.x > position.x
    Vel.x =  -speed
    Scale.x = 1