# Distance between objects

Get help using Construct 2

### » Fri Jan 27, 2012 10:21 am

Hi guys and gals,

How do I keep a distance between 2 objects?
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Fri Jan 27, 2012 10:37 am

I'm not sure if this is the "best" way to do it, but I used the following:

System - Every tick ---> ObjectA SetPosition(ObjectB.X, ObjectB.Y)

Hope that makes sense... Basically this will keep setting the position of ObjectA to that of ObjectB. You can add some pixels to the X or Y axis if you like.

Rasmus2012-01-27 10:38:35
B
5
Posts: 12
Reputation: 774

### » Fri Jan 27, 2012 10:38 am

you can determin the distance useing the command "distance (x1,y1,x2,y2)" and the react according to the result
B
42
S
19
G
12
Posts: 723
Reputation: 13,876

### » Fri Jan 27, 2012 10:43 am

Cheers peps!

Ill give them booth ago!

Rasmus: That's seems simple enough!

Weishaupt: Where is this command "distance (x1,y1,x2,y2)"?
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Fri Jan 27, 2012 10:46 am

this is somehting you have to "type" to see it. Create an event -> System -> Compare two variables -> and type "distance" in the first data field...you should see a buble showing the exact syntax
B
42
S
19
G
12
Posts: 723
Reputation: 13,876

### » Fri Jan 27, 2012 10:48 am

Ah right I see it!

So then all you do is set the distance (x,y) between the two objects.

How does it new the position of each object without the object name?2Bdigital2012-01-27 11:01:03
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Fri Jan 27, 2012 11:02 am

no behaviour needed....

B
42
S
19
G
12
Posts: 723
Reputation: 13,876

### » Fri Jan 27, 2012 11:13 am

Can't seem to get it to work, I must be doing something wrong!

I have these 3 images and I want them to keep distance from each other, how do I achieve this?

capx file would be nice, so I can see exactly what's happening in the events.
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

### » Fri Jan 27, 2012 11:20 am

Pal - I dont have a CAPX wich I could send you. I just opend c2 to shoot that picture, but if you post your capx and let me know what you are trying to do, i could edit your file
B
42
S
19
G
12
Posts: 723
Reputation: 13,876

### » Fri Jan 27, 2012 11:27 am

Here is the file:

capx

Its all touched based at the moment as I'm creating it for tablets and mobile phones.

I have these 3 stickmen which have been sliced into individual parts (Head, Body and Legs). The parts are triggered to move when touch is activated, there are 3 hit areas behind each of the body parts (Head, Body & Legs).

I have a 4th hit area which I want each body part to snap to if it comes into collision/overlaps with hit area 4, the problem is when I do this, all the body parts come together, I want them to keep safe distance between each other like there are when you load the capx.

Hope that makes sense...
B
5
S
1
G
1
Posts: 111
Reputation: 1,122

Next