How do I pick Colliding Instances?

  • Hi,

    maybe this has been asked before, but how can I get the instances (IID, UID or custom variable) of 2 colliding objects of the same type?

    [attachment=0:1nzetvxe][/attachment:1nzetvxe]

    Thank you very much!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you look in the "Falling Blocks" file in the examples folder, they show how to use a function with 'Pick instance with UID'.

  • xeed :

    if two objects collide, thos two are already picked by this event. Now you have to decide, which one you want to destroy or do something with it.

    Let's say, you want to pick the first appearing bullet, and keep the newer one. That is easy:

    You can pick the top or bottom (z-index) one very easily by the expression "Pick top (or bottom) instance". Since z-index is influenced by order of appearance, that means the older (or newer) can be made disappear.

    Let's say, you want to destroy the one with lower speed:

    Pick the top instance of the two colliding, just as before, than set a local variable to it's speed. You need this, since bullets to bullets comparison confuses things obviously. (Bullets.Bullet.Speed < Bullets.Bullet.Speed would compare it with itself, so does not work like that.)

    Now you can compare to that local variable easily, see pic below for more details. (Of course it can be also health, or whatever attribute you compare of the two.)

  • MultipleChoice

    This helps a lot, many thanks!

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