Collision Detection with Arrays

In this thread from 2017 ( Scripts That Check Multiple Objects ), it was suggested to check collisions against multiple objects with an array. I am trying to do that, but not having much luck. Could anyone spell out to me how I would do that? I have an array set up for ground objects like this:

groundObjs = [];

and then I have each ground object add itself to that array. Everything is working up to that point, and using console.log to list everything in that array is showing that all of the ground objects are being added properly, but now I can’t figure out how I would check for collisions against any/every object in that array.

Any advice for doing this? I’m using the Alpha Editor. Thanks in advance!

1 Like

In your object array store your wick objects.

To check collisions within that array use the update function inside of a clip you want to check collisions with.

I’m doing this on mobile by memory but I believe this is how,
Use a loop to check:
for (i = 0; i < groundObjs.length; i++) {
if (this.hitTest(groundObjs[i])) {
– Colliding with something in the array
}
}

3 Likes

If you have time later @MisterMender I would love to see a .wick file example :)

Nevermind, Luxapodular already posted one…
I find that I learn best by example :slight_smile:

2 Likes

Yep, that’s about it! Here’s a little example that does this with a few walls. (There is a hitTest bug in the live obj.hitTest function, so this may not work perfectly as expected, but it gets the idea across for now!)

hitDetectionForMultiple.wick (2.6 KB)

Also @GoodL, this gets WAY simplified once we add in tagging… we unfortunately got caught up last week, but it is on our agenda. Sorry it’s taking so long.

3 Likes

No worries, thank you so much! I really appreciate it :slight_smile:

3 Likes