[Solved] How do I pick objects within a family?

0 favourites
  • 10 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Let's say I have a Family with 100 Sprites randomly placed on the screen.

    I want to pick all of objects in that family that is closer than 100px to another one in the same family, if there is any?

    In my mind this would work but it doesn't really.

    Pick by evaluate. distance(family1.X, family1.Y, family1.X, family1.Y) < 100

    It seems like it's always true, since itself is always closer than 100px to itself.

    So what is the smartest way to filter out itself in the evaluation?

    Expected: If any objects in a family is closer than 100px to eachother = True (Picked)

  • This didn't seem to work either as expected. Is there no way to compare and pick the way I'm trying?

  • Another test that didn't work. What am I doing wrong?

    capX

    https://dl.dropboxusercontent.com/u/20560446/Scirra/distancepicking.capx

  • Finally solved it. Had to create a second family with identical objects in it.

    Sharing if anyone finds it useful.

    But if anyone has a smarter solution that doesn't involve 2 families with same objects, please let me know.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In the first attempt, you locked the first created sprite to the mouse. Then you looped trough all sprites, and feeded all those to the function.

    The function is a NEW TOP-EVENT, so it forgets (by design, and luckely so) any previous picked lists. So the function picks out of all sprites those that that have a differend UID then those you feeded to the function. And yes, including the one you locked to the mouse. But also all others. Then loops trough them, and compares the distance. As a result they kinda flip-flop. In one loop one gets set 50 % opaque, in the next loop that same one gets back to 100 %. You needed to compare to only that one that you locked to the mouse.

    In the second attempt. The for each runs on each member of the family, because there is no previous picked list. There is also no previous picked list for Sprite. So it picks out of all sprites those that dont have the same UID. Wich is just all of them. So basecaly it runs trought all family members and for each famely member it runs trough all sprites. If you have 100 sprites, that would be a loop that counts 100 * 100 times. Again creating some flip-flop thing.

    Here is a working example. I used drag and drop to be able to explore more situations.

    https://drive.google.com/open?id=0B1SSu ... HUydDNQcmM

    As you see i feed to the function only the postion of ONE sprite. In the function i pick all but that one sprite. Then i compare the distance of those only one time against the position of that one sprite.

  • In your last post, that should set each sprite that is less then 50px away from each other opaque.

    That works if the sprites in the layout are far away from eachother, creating the illusion that those that are close to the one that is locked to the mouse are picked.

    That works if that was what you intented to do.

  • In your last post, that should set each sprite that is less then 50px away from each other opaque.

    That works if the sprites in the layout are far away from each other, creating the illusion that those that are close to the one that is locked to the mouse are picked.

    That works if that was what you intended to do.

    Yeah... Last test does what I intended it to do. but is a bit heavy on resources (for each) as it goes through every single family1 object every tick and checks if there is any object in family 2 within the specified distance. If I have a lot of objects that's gonna be super heavy, so it's not optimal.

    Now I'm looking for a smarter (more performance friendly) way to do the same thing with events. I know i could use collisions to do something similar, but I'm trying to do sort of a customized collision detection based on distance between objects or within a radius in a family, and not a collision polygon.

    Maybe the most efficient way would be to add some steps or increment? First i can start by checking every 0.5 seconds if somethinng is within a slightly larger radius. I could create a variable (check rate) that is based on the distance between objects, that gets smaller as the distance shrinks.

  • Did you even open my example ?

  • Did you even open my example ?

    I did. It worked in a similar fashion. But I'm going to have lots of objects that are going moving around randomly on the screen. And when they get close to eachother they change direction.

  • Then you gots the solution, there is not really a more performance friendly solution. As long as you dont check for overlaps/collissions in the whole loop, you be fine. Sorry i got on the wrong leg because of this sprite you dragged arround.

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