Comparing x position of an object

Hi guys. I try to make a enemy, with a very basic behiavor.
The Behiavor is: If the enemy is more than 50 pixels at the left of the main character, it will stop moving and start moving to the right and viceversa.
I’ve done all except by the “is more than 50 pixels at the left of the main character” part. I don’t know how to do that.
Could you guys help me? Its important since if this is not done, the enemies will stick at the bottom of my character.
Also guys, sorry for my crappy english. If you dont understand something, i’ll explain better.

You can use use the compare 2 numbers condition. Where you compare the enemy’s X position and character’s X position.
If Enemy’s X < Character’s X, it means that the Enemy is to the left side, and viceversa, then implement the “distance from object” condition as well.

1 Like

Try a condition like:

Enemy.X() < Player.X()

And then the event would be whatever code you’ve got to move the enemy right. Another condition using “greater than” to move the enemy left.

Edit: looks like @Eliath_x beat me to it by a minute.


Thank you everyone! This was very helpful.