# What is the best way to define a "range" between X

0 favourites
• 9 posts
• ...coordinates.

Essentially, my enemies are going to start using JUMP randomly if the player doesn't keep moving (makes camping harder).

However, I don't want them to just be jumping all over the place, I want them to try and jump when close to the player - within a range of the players X coordinates.

But I have no Idea how to define a range I assumed the logic would be like this:

If "enemy" is within range: Player.x-100 to player.x+100 then "Jump"

but I can't seem to work out how do define this range.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• use distance expression , but there is another way with invisible sprite.

• distance(x1, y1, x2, y2) Calculate distance between to points

so in your case on the enemy sprite

System every tick Compare variables "Range of vision" to distance(currentplayerposition.X, currentplayerpostion.Y, self.x, self.y)

if less than range of vision -> enemy jump

• Also, if you're just planning on calculating the X distance you can substitute Y with 0.

distance(player.X, 0, enemy.X, 0)

• or even simpler: abs(player.x-enemy.x)

• I think the only one who can make that even simpler now is R0J0hound. <img src="smileys/smiley17.gif" border="0" align="middle" />

• whats this ABS expression?

• Oh and thanks! I appreciate it.

• abs() turns a negative number into a positive.

There's a short description for each one if you click through the expressions window. (the one that's slightly faded unless you mouse over it)