How to do AABB selector to get object instances?

0 favourites
  • 4 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hello everyone.

    I am wondering how I can use the AABB search method (or a built-in game-world search method?) to get an array of references to the object instances within a certain radius around a given tested object.

    I know Box2d has this built in but I haven't seen anything in the Construct 2 documentation saying how to access it/use it in the events.

    Would appreciate any assistance. Thank you. :)

  • Few methods:

    Create invisible sprite with radius you desire. Spawn it on top of test object and check for objects that overlap the invisible sprite. Now you have all the objects within desired radius picked.

    Another way would be to calculate distance of each object from the tested object and save them as instance variables for those objects. Then pick by comparison, where object.distanceVariable < desired radius. Again, you'll have all objects within certain radius picked.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can't without a plugin.

    The closest you can achieve without you events getting too complex, is to use a sprite with a circular collision polygon and do something like

    // flatten the array
    -> Array: set size to (0,1,1)
    + myObject is overlapping circularDetector
    + foreach myObject
       -> Array: push myObject.UID in X axis

    Then you have the UID of all the object whose collision polygon overlap the circularDetector's one.

    The UID is the closest thing you'll have to a "reference" in c2's event sheet system.

    Also it's an unperfect solution since your circularDetector won't have a perfect circle has a collision polygon but a... polygon (by default an octogon)

    And it's inperfect because it's not really an AABB test but a collision polygon against collision polygon.

    But if you set the collision polygon of myObject to bounding box... you'll be closer to what you asked (:

  • Thank you guys. :)

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