# Distance

Get help using Construct 2

### » Sun Aug 05, 2012 4:06 am

How do I compare the distance between two objects only by their X, and not their Y?Kid4lynn2012-08-05 04:54:10
B
14
S
3
G
1
Posts: 44
Reputation: 1,177

### » Sun Aug 05, 2012 5:13 am

you could use distance( ) expression but just leave the Y values as 0

or just do
objectA.x - ObjectB.X
and put it in abs( ) if you need it to stay a positive number.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Sun Aug 05, 2012 6:55 pm

@keepee These are good ideas.

But when using distance its like "distance(player.x,player.y,enemy.x,enemy.y) --- so how would I leave the Y as 0?

I'll try the second method right now.
B
14
S
3
G
1
Posts: 44
Reputation: 1,177

### » Sun Aug 05, 2012 7:53 pm

how about player.y and enemy.y being just zeros?
B
37
S
11
G
6
Posts: 962
Reputation: 11,259

### » Sun Aug 05, 2012 7:57 pm

@Rory You mean, put them on the layout at Y=0, but move their X's?

You're losing me here... lol.
B
14
S
3
G
1
Posts: 44
Reputation: 1,177

### » Sun Aug 05, 2012 7:58 pm

No, no, no. Instead of putting Player.Y into the formula, you put 0.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,185

### » Sun Aug 05, 2012 7:59 pm

@Mipey Oh that works? sweet.. thanks
B
14
S
3
G
1
Posts: 44
Reputation: 1,177

### » Sun Aug 05, 2012 8:22 pm

It's basically |Player.X - Enemy.X|
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,185

### » Sun Aug 05, 2012 8:32 pm

@Mipey Im trying to make a LOS based AI for a platformer, so far its buggy and hardly works, this is difficult. Im giving myself some credit for making it this far and hardly knowing anything about coding.
B
14
S
3
G
1
Posts: 44
Reputation: 1,177

### » Sun Aug 05, 2012 8:44 pm

It's more about math than coding, trust me :)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,185

Next