# How do I get the distance between 2 objects?

Get help using Construct 2

### » Fri Jun 19, 2015 11:48 pm

How do I get the distance between right side of first object and left side of second object? This will be usefull to I make this:

Liked something I say?
B
28
S
9
G
4
Posts: 359
Reputation: 4,246

### » Sat Jun 20, 2015 12:20 am

distance(First_Sprite.BBoxRight, First_Sprite.Y, Second_Sprite.BBoxLeft, Second_Sprite.Y)

But i think you are overcomplicating this a bit
B
160
S
69
G
43
Posts: 2,606
Reputation: 36,304

### » Sat Jun 20, 2015 12:43 am

distance(user1.x , user1.y , user2.x , user2.y)

if character not mirrored distance(user1.x , user1.y , user2.x , user2.y)less then 200 trigger follow ( move towards angle 2 pixel)

if character mirrored distance(user1.x , user1.y , user2.x , user2.y)less or equal 200 trigger follow ( move towards angle 2 pixel)

repeat the code for both of them depends if you want them to follow each other or not!

if user1.x = user2.x or user2.x-20 move forward towards user2.x +200 then trigger follow again ! to pass through and then come back is a bit tricky, the whole process

@DaniellMesquita
the thing is you can also use LineOfsight that does basically the same thing what i said above! as @Shadowdawnz said! but then you will need a trigger event or switch like when they face each other to be turned on but move forward then if distance is bigger or out of sight start following each other the thing is the whole process will make both characters wabble around each other at some point !

how ever line of sight is a bit buggy and may not work all the time, my fish game template even though i could use line of sight, i dident was creating this weird comparisons and then wouldn't attack my hero fish! so i used the normal distance (x1,y1,x2,y2)
Last edited by gamecorpstudio on Sat Jun 20, 2015 8:42 pm, edited 3 times in total.
B
79
S
24
G
69
Posts: 1,356
Reputation: 44,125

### » Sat Jun 20, 2015 4:50 am

@gamecorpstudio, sorry, but I can't understand this code. How this will work in my .capx?
Liked something I say?
B
28
S
9
G
4
Posts: 359
Reputation: 4,246

### » Sat Jun 20, 2015 5:13 am

If i understood your post correctly Daniel, you could try using the Line of Sight behavior.
If the follower is in the FOV of the player, then player can interact with follower. Maybe have the follower with Line of Sight as well, so if both the player and the follower are in each others FOV, then they are able to interact with each other.
B
21
S
5
Posts: 44
Reputation: 1,644