Scripts That Check Multiple Objects

I was considering making a platformer just for fun, but I’ve had difficulty with scripts that need to reference multiple objects. The built-in collision check, for example, can check one object with a certain name. It feels like I’m missing functionality, but I’m not very familiar with Javascript. Is there a tool I can use to organize my clips??

Hey @Connorses! Thanks for joining the forum.

For the collision detection question, would being able to check against multiple objects (say in an array) give you the functionality you need?

For the organization question, how would you want your clips organized? @zrispo and I are working on finalizing how clips will interact with the Asset library and would love your input.

It might be a while (a week or two) but I’ve been planning to give the scripting API a much needed update, as well as make a bunch of examples that use code (so like a sidescroller, space shooter, small clones of games).

Once those examples are up, it should be much easier to make simple games with with, as you’ll be able to open up the examples and rip out what you need!

If I create copies of an object from code, then yes, I can add them to an array and check them all each frame via for-loop. This is different, of course, if you want to place a lot of walls on a frame by hand and check collision with them all since they must have different names. I did find a solution though! You can to put a script on each individual wall that checks for collision with the player, and sets some variable in the player like “player.hit = true”. So, really, there’s nothing stopping me from duplicating my wall a bunch and making maps that way. I think there’s definitely room for improvement.

There’s also the option to make all the walls into one Clip and then hit-test that Clip against several points arranged like a bounding box around the player, but performance may be an issue.

If I put all the walls into a clip it will have one big rectangular bounding box. ??

Ohhh, yeah that’s right. I assumed Wick had an option like Flash’s to hitTest the exact shape of an object against a point. But actually there’s just these two types, and they’re vague: :confused:

hitTestType : String - Type of hit detection to use. Can be ‘rectangles’ or ‘circles’. If no hitTestType is given, hitTest defaults to ‘rectangles’

Hmm, we’ll talk through the hitTest API during this session @zrispo was talking about. We’ll try to figure out a better way to explain them as well!

At the moment, those hitTestTypes are referring to rectangular hit detection (based on the bounding box of the object) or circular hit detection (based on the width and height of the object from the center.)

Never mind, I looked at the hitTest example, and apparently object1.hitTest(object2) will detect collisions between the exact shapes of “object1” and “object2”. :smile: Very helpful.