When overlapping 2 or more instances how do I select the closest one

0 favourites
  • 5 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • I've been trying to do this for the last two days, and at this point, I think I am so wrapped up in it that I must be missing a very simple and normal way to do this.

    Problem:

    I've got a family of sprites, when overlapping one of them I need to select that instance (creating an outline when selected and deleting it when not selected/overlapping). When an instance is selected and a key is pressed I need it to change states and do something.

    The issue here is when I am overlapping more than 1 instance it either changes both of their states or will keep the first one I overlapped with selected even if I move out of its collision area while still overlapping the 2nd instance.

    I feel like I've tried all the obvious ways of picking the closest instance to me when 2 or more instances are selected, but obviously, I am missing something. Any suggestions would be great! This is for a game jam, so if I can't figure it out in the next couple of days I'll just have to leave it how it is...

    Tagged:

  • There is a pick nearest/furthest instance condition if that will work for you here.

  • There is a pick nearest/furthest instance condition if that will work for you here.

    Yeah, I was trying to use that but I think I had just been working on it for wayyy too long and needed to take a step back and gut the events to simplify everything.

    After neatening it up, I've to it working better. But the outlines are still a bit wonky. It'll still have two of the sprites outlined at the same time. Here's a screenshot of the events

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This sort of thing happened to me in a previous project. Assuming that it's at least picking all of the possible choices (that's one problem, the picking / grouping issue sometimes causes confusion), then I would have thought pick nearest would work. If not, I'd probably do it through the debugger and maybe calculate the distance myself (there's a distance expression that works). If it's not picking correctly with pick nearest, are you sure the one you want is even included in the picked group? And if so, maybe the origin points are out?

    I just re-read and see that the issue is that it's picking two instead of one? If you're doing picknearest, it should always pick one. So if it's picking two, are you sure the event isn't being run twice (happened to me before!)

  • Managed to get it to work! I think I was just over complicating it and using the pick nearest incorrectly. Got help from the construct discord and someone gave me the answer to create an instance on the player to hold the UID of the nearest sprite in the family and then based on who matches that UID it'll run the events.

    Not sure if the screenshots are showing, but I'll try to attach on here.

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