How do I Add and Subtract the X and Y Coordinates

  • 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.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Glad it worked out. :)

    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. :]

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)