# How do I Add and Subtract the X and Y Coordinates

Get help using Construct 2

### » Wed Jun 08, 2016 12:14 am

Two objects, their origins in the middle.
To put Block1 on top of block2, I tried to to add their halves and subtract it from block2's Y.

Block2.Y - (Block2.Height /2) + (Block1.Height/2)
This subtracts Block2's height instead of its Y position.
B
9
S
4
G
1
Posts: 4
Reputation: 1,233

### » Wed Jun 08, 2016 6:38 am

Hi Blamitall,

If I understand correctly, I think you might want the following:

Set Block1.Y to:
Block2.Y - ( (Block2.Height /2) + (Block1.Height/2) )

This adds the radius of B1 and B2, and then subtracts that whole value from the B2.Y.

Place & move method
Another handy approach in this kind of situation might be, to use two actions:
1. B1: "Set position to another object", use B2 as the target object.
2. B1: "Move at angle" a distance of ( ( B1.h / 2 ) + ( B2.h / 2 ) ), at angle -90.

This approach separates out the relative offset, which can help make the code a little easier to understand/edit at a glance.
It's not quite as efficient as setting the cords directly, but the slight difference in efficiency will likely only be noticeable if you do it 10,000 times a tick.
So this method isn't strictly better or worse, it just has different pros and cons.
B
34
S
22
G
8
Posts: 352
Reputation: 6,785

### » Wed Jun 08, 2016 3:28 pm

AWESOME! You solved my problem,Thanks!

I also noticed I had events I didn't need, which stopped it from working. Amazing what taking a break will do for the mind.
B
9
S
4
G
1
Posts: 4
Reputation: 1,233

### » Thu Jun 09, 2016 12:37 pm

And oh, man, I know what you mean about taking a break, coming back, and beholding the madness of yesterday's 4am attempts at productivity. :]
B
34
S
22
G
8
Posts: 352
Reputation: 6,785