# I don't understand Distance expressions. Help?

Get help using Construct 2

### » Thu Aug 29, 2013 4:01 am

I suck at math and I'd like to make my enemies do more than just walk back and forth all the time. Can someone tell me how to use the distance expressions?
B
10
S
4
G
1
Posts: 159
Reputation: 1,933

### » Thu Aug 29, 2013 4:19 am

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

It's pretty self explanatory. Say you have a player and an enemy
distance(player.x, player.y, enemy.x, enemy.y) will return the distance from those 2 objects.

So if you want the enemy to shoot when the player is closer than 200 pixels:

If distance(player.x, player.y, enemy.x, enemy.y) < 200
- Trigger enemy shooting event/function/group

B
101
S
32
G
12
Posts: 1,549
Reputation: 22,103

### » Thu Aug 29, 2013 12:44 pm

B
10
S
4
G
1
Posts: 159
Reputation: 1,933

### » Thu Aug 29, 2013 1:05 pm

How do I put the distance first? Do I need to select the player or the enemy first?
B
10
S
4
G
1
Posts: 159
Reputation: 1,933