How to make it so an object can hit 2 other objects and react?

Hello i have a question how do i make it so an object can hit another object?
example:
if (this.hits(object2, object3)) {
//code
}

but when the character hits object3 it doesn’t work
im new at coding and im experimenting it on wick editor
thanks for passing by :slight_smile:

1 Like

In coding, you can type “||” to say “or

For example, here’s this:

if(this.hits(object2) || this.hits(object3)){
// Type code here
}

The code above basically means:

If this hits object2 OR if it hits object3, then do this...

You can also use “&&” to say “and,” but then the object will need to be hitting object2 AND object3 at the same time for the statement to return true. If this is what you want, then just replace the “||” with a “&&

2 Likes

Thank you very much, this is what i need! :grinning:

Hey I have a question if you don’t mind, what’s the difference between .hits and .hitTest ?
also is there a way to change the transparency of an object on code?

hits” is newer. The “hits” code can be edited to make the hitbox of objects a circle, square, or “convex.” It can also give an array of intersection points when the objects hit, and it has more options than the “hitTest.”

hitTest” is “older”, and the hitbox of objects with this function is just a square. It doesn’t have other options, but anyone can still use it.

Yes, the transparency of objects can be referred through code as “this.opacity

An example:

this.opacity-=0.3;

Thank you so much :) this really helped a lot, but how to change the hitbox of an object as you said?
oh and i got this question that came up from my head, is it possible to change the canvas size using code?

No, but you can change the zoom level from code

this.project.zoom+= NUMBER

Put this code in default script:

let hit = this.hits(test, {
    mode: "SQUARE", // Set this to "SQUARE," "CIRCLE," or "CONVEX" '
    intersections: true, // An array of intersection points, set to true or false
    overlap: true, // Set true or false
    offset: true // Set true or false
});

Hey thank you so much!! :)

dosen’t work :frowning:

try using || instead, also this is not capital I

I think you are referring to the “or” operation in JS.

that key is when you press “shift” and \ at the same time. on my keyboard, and probably on most, if not all, other keyboards, it is to the right of the square and curly brackets.