How do I 'Choose' the nearest object?

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi.. I'm totally new, needed some help to complete my first game.

    This game that I am making, imgur.com/1ZJaEWr

    It's a easy drag and drop objects to the correct areas, (example Box1 is AppleBox, Box2 is OrangeBox), drag drop the Orange into the correct box.

    Short Version:

    There are scores, dropping to the correct box gives +5, and the wrong box -5, however, if you were to drop in between of both box, the score will be 0 (+5 and then -5).

    What I wanted is, how do you choose the nearest object, like, if the Orange is nearest to the OrangeBox, drop in the OrangeBox instead of both (when it is in the middle, or somewhat touching both box)

    What I'm doing/currently have

    Orange on dragdrop drop and Orange is overlapping OrangeBox, System Add 5 to score

    Orange on dragdrop drop and Orange is overlapping AppleBox, System Subtract 5 to score

    More details:

    When placed in the wrong box, the object will destroy and create another one at the "cart",

    which putting in the middle, created one orange in the orangeBox, but have a score of 0, and the orange is re-created at the "cart" again, this is a huge problem for me. ):

    (Maybe I shouldn't be using overlapping? or is there a choose to overlap the nearest box, or anything)

    P.S. I am totally new, just started learning this software a few days ago.

    If possible, would like to see an example, or a clear explanation of a solution/solution that work

  • help please.. anyone..?

  • On overlap should work fine.. sounds like you have something else going wrong.

    If I was making this I would use 2 invisible sprite "zones" one covering each box and use the on-overlap condition. I would however use a double condition test for overlapping both (ie. is overlapping spriteOrange and spriteApple).

    You could get more complex and grab the orangeBox.X and the AppleBox.X and then test against their values to determine which one is closer to the apple.x or orange.x but for a simple project like this I would just use overlapping sprites.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yah that's what I did, (without the double condition test of overlapping both), there is a image link to show my project.

    and yes, I kinda need/want that distance test to see which one is closer and then apply it to the box

    edit: i am using invisible overlapping sprites. like i mentioned above, if you overlap both boxes, it activate its event for both boxes (score +5 then -5)

  • Pop the capx ?

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