Pairing objects at runtime

This forum is currently in read-only mode.
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • How would I go about pairing two instances of different objects at runtime, like containers, but chosen at runtime.

    What I need is for on collision between object1 and object2, object1 always sets position to object2. (for a while anyway) and these two objects need to stay connected like this. There are multiple object1's and object2's and others pair together aswell.

    I've tried things with object IDs but couldnt get it to work, the best I can do to pick the instances on overlap between these objects, but this bugs out constantly.

    Reminiscent of when I've tried pairing things without containers (horrible, horrible )

  • Is there always one object2 attached to an object1? If so, containers will do the job. Otherwise, if you explain what you're trying to achieve a bit more, we could come up with a bit more of a specific way to help you...

  • No they're not always paired, none are paired at the start of the frame, then they pair up as they collide with eachother.

    Basically like with containers, if object1 and object2 were in the same container, then doing:

    always-> object1 set position to object2

    the instance of object 1 would set its position to the instance of object 2 it is assigned to via the container

    I need this sort of effect, but for the instances to be paired up at runtime.

    what I have is loads of object1s and loads of object2s floating around the screen, and I want when one instance object1 collides with an instance object2, these two instances are paired, and I can just add an event to anything else where I need one object to select its assigned instance of the other.

    Like having object1 collides with object2 -> object1 sets private value 'OBJ' to object2.OID

    then,

    when object2's OID = object1.value('OBJ') (pick these two instances) -> object2 set position to object1

    I can imagine there is a simple way to do it, but as i said the best thing i've been able to come up with is

    object1 overlaps object2 -> object2 set position to object1

    which bugs out if for example object1 moves fast

    Maybe it could be done with for all object loops? I've tried sortof placing for all object 1 and for all object2 in the event arbitrarily and shuffling them about with no success (unsuprising really).

    Hope I've explained better

  • I was actually working on something similar today, so I whipped up a quick example for you:

    Object pairing

    It's commented, so it should be fairly easy to understand. Hope that helps.

  • I love you

  • [quote:2g3so7ue]FAGgatron: I love you

    Haha i bet you do XD, nice example link.

  • Glad I could help.

  • I was actually working on something similar today, so I whipped up a quick example for you

    Great example! For Each is the key there, and that's pretty much how I'd have done it as well.

    One minor change though: in event 4, if you replace the random number with the object's unique ID (object1.UID) - that makes it bulletproof. With randomness, there's always the tiniest possibility it'll duplicate IDs. With object unique IDs, that never happens.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • in event 4, if you replace the random number with the object's unique ID (object1.UID) - that makes it bulletproof.

    Did you try this? - because when I do it it doesnt work, (my original problem) they don't set to anything if you set it to object1.OID and they all set to one of the object1's if you set it to object2.OID

    I am assuming this is a bug???

  • Did you try this? - because when I do it it doesnt work, (my original problem) they don't set to anything if you set it to object1.OID and they all set to one of the object1's if you set it to object2.OID

    I am assuming this is a bug???

    That's probably because you put OID instead of UID. The OID of object1 would be the same for each instance of object1. The UID is that instances unique identifier, so every instance has it's own UID. Hope that helps.

  • ahhh it all makes sense now, thanks

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