How to do AABB selector to get object instances?

Get help using Construct 2

Post » Mon Aug 05, 2013 1:25 pm

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. :)
Posts: 2
Reputation: 154

Post » Mon Aug 05, 2013 1:55 pm

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.
Posts: 756
Reputation: 7,352

Post » Mon Aug 05, 2013 1:57 pm

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[code]// flatten the array
-> Array: set size to (0,1,1)
+ myObject is overlapping circularDetector
+ foreach myObject
   -> Array: push myObject.UID in X axis[/code]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 (:Yann2013-08-05 13:57:38
Posts: 1,494
Reputation: 16,660

Post » Mon Aug 05, 2013 2:23 pm

Thank you guys. :)
Posts: 2
Reputation: 154

Return to How do I....?

Who is online

Users browsing this forum: JGblkshot, mongol and 5 guests