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

Get help using Construct 2

» Tue Oct 23, 2012 3:23 pm

...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.Awakening2012-10-23 15:25:15
B
9
S
3
Posts: 148
Reputation: 1,738

» Tue Oct 23, 2012 3:26 pm

use distance expression , but there is another way with invisible sprite.
B
49
S
15
G
6
Posts: 795
Reputation: 12,085

» Tue Oct 23, 2012 3:51 pm

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
B
54
S
22
G
8
Posts: 850
Reputation: 10,491

» Tue Oct 23, 2012 6:01 pm

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

distance(player.X, 0, enemy.X, 0)
B
65
S
21
G
8
Posts: 305
Reputation: 9,156

» Tue Oct 23, 2012 8:15 pm

@TL22 or even simpler: abs(player.x-enemy.x)
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

» Tue Oct 23, 2012 10:03 pm

I think the only one who can make that even simpler now is R0J0hound.
B
65
S
21
G
8
Posts: 305
Reputation: 9,156

» Wed Oct 24, 2012 1:44 am

whats this ABS expression?
B
9
S
3
Posts: 148
Reputation: 1,738

» Wed Oct 24, 2012 3:03 am

Oh and thanks! I appreciate it.
B
9
S
3
Posts: 148
Reputation: 1,738

» Wed Oct 24, 2012 9:29 am

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)
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Return to How do I....?

Who is online

Users browsing this forum: duke2704 and 25 guests