How do I access collided family's object?

  • I have condition:

    If object of family "A" is overlapping another object of family "A", then create revolute joint from one to another.

    1 - works

    2 - doesn't work

    It takes all the objects of this family with boolean set to false, so when i have just one object of this family with boolean = false and multiple objects of this family with boolean = true, it correctly picks this one particular object. But how to create joint from it to another object of the same family (these with boolean = true)?

  • Use a second family with the same objects in it. Then you check family A against family B.

  • I'm afraid that it'll not work in my case - objects of family A are objects for placing in world and are created at runtime. Example with building a wall:

    1. Object "brick" from family "Placeable" is picked by clicking a button and created in layout.

    2. "brick" is placed on ground and it changes it's variable "placed" to true.

    3. Another "brick" is picked (and created at runtime) - now, i want to place it on top of previous "brick" (in my case, when they're overlapping, so it's like welding) System correctly detects when they're overlapping, but it doesn't create revolute joint to this previous brick.

    I've thought about having another family/container with only "placed" objects and checking against it, but it will need possibility to add objects to family/container at runtime - and right now it's impossible, am i right?

    (That was only a exmaple, in my case i need a limited revolute joint)

  • Families have nothing to do with instances. You have a Family now, You can make a second duplicate, and it will work the same way.

  • OK, I've just changed my mechanics so i don't need this approach anymore, but thank You

  • ye, the timing.

  • Families have nothing to do with instances. You have a Family now, You can make a second duplicate, and it will work the same way.

    It depends... You can't actually duplicate a family if it has family instance variables. If, in his example, the "Placed" variable was an instance variable of the "Placeable" family, then he can't duplicate the family to use that trick, because objects can't have 2 instance variables of the same name, so the second family can't have the "Placeable" instance variable, and then you won't be able to access the "Placeable" variable of any object in the duplicate family.

    The OP's problem is actually one of the reasons why I suggested having aliases in Construct 2 (topic: scirra.com/forum/construct-2-general_f146 but Ashley already dismissed my idea because of performance issues. Maybe if the engine supported somehow assigning object references to local variables, or some kind of "ObjectReference" plugin which serves the same purpose.

    In any case, OP, how did you sidestep the issue? It would be useful to know for future reference

  • Yeah, object references, maybe possibility to create local variables of any object's (family?) type (not only boolean, float & string) will be very useful. It's quite hard to get into some Construct 2 areas when coming from object-oriented programming

    As to my issue, i've re-categorized a lot of objects (it's not exactly about building walls) and changed whole gameplay a bit, but basically i'm creating an extra empty sprite (collider) in place where any of placeable items is placed - and every new placed object creates a joint to these colliders (so it's checking for overlapping with these colliders, not with "Placeable" objects)

    Maybe not a perfect solution for building structures, but works in my case.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just FYI, I think this topic is covered here: https://www.scirra.com/tutorials/556/un ... o-families

  • Just FYI, I think this topic is covered here:

    While that tutorial is extremely helpful, it doesn't solve this particular problem, because the "Create limited revolute joint" action on the Physics behavior takes an 'object reference' as a parameter, which you don't have when using the solution the tutorial proposes.

  • Wow, I hate to be the guy that didn't read the post properly

    Thanks for correcting me.

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