Picking an object that is in two specific families

This forum is currently in read-only mode.
From the Asset Store
Footsteps SFX Two contains 450 sounds of steps and jumps on different surfaces.
  • Hello,

    I am not sure about this, maybe I am just tired, but I have a problem:

    I have one family for each player (Red Player, Blue Player, etc.). Those families hold all structures and units in my game.

    Now, I have separate families for those as well (Units for my units and Structures for my structures).

    What I need to do is this:

    Get the coordinates of my mouse cursor (I know, MouseX and MouseY) and see what friendly structure is closest to it.

    For example:

    I am the blue player, my cursor is closest to a red structure. However, this is not the one I want to pick in my game code. I want to ignore all structures but the blue ones and there pick the closest one.

    The way I see it, my only means of doing so would be to split the player families further, so that in addition to Units, Structures and Blue Player I would get Blue Structures and Blue Units.

    If at all possible, I would like to prevent that for sanity's sake.

    Any ideas? Maybe something I just overlooked?



  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • + On Mouse click

    + Blue: Pick closest to MouseX,MouseY

    Punt the garden gnome

    I'm not really sure what you describe, but if you want to pick the closest member of Blue family to the mouse coordinates, that is the way to go.

  • Thanks for your reply.

    I don't want to pick the blue member closest to my mouse, I want to pick the blue member closest to my mouse that is a structure.

    It would look like this:

    For all Structures in Blue Player

    Pick object closest to X/Y (MouseX, MouseY)

    Just that I don't think Construct supports something like that without using arrays. However, using arrays for this just feels...dirty. I was looking for a more elegant way to handle it.

  • I see, you just want to pick structures within Blue family... Hmm.

    Well, personally I prefer private variables when it comes to situations like this, because this allows me to switch them around (like capturing a building, which would then from reds go to blues).

    So, if you gave your structures a private variable, say 'Faction', you'd just do it like this:

    + Structure('Faction')="Blue"

    + Structure: Pick closest to MouseX,MouseY

    Drop a stink bomb onto neighbour's doormat

    Basically it first selects the structures that belong to Blue player, only then it selects the one closest to mouse. Hope this helps.

  • This was exactly my question, thanks

    I wasn't sure if once you picked a set of objects by saying

    Select all structures where faction = "Blue"

    the next picking of object (pick object closest to...) would take place in that already picked set of objects or in a fresh, unfiltered set of all objects in the family

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