How does the "(if) hits" command work?

Fill this out this info to make it easier for the community to help you! If you don’t fill out this information, your post may be deleted or removed.

What Wick Editor Version are you using?
Ex. 1.19.

Describe the Problem
In my game, there are arrows that will be flying at the controllable character. I was wondering if there was any way to create a command where, if the arrow intersects the character, it will change the score (a text that I will use that will say “hits”).

I saw that there was a command on WickEditor that is in the “objects” section, which says (if) hits. Maybe I can use that somehow, but I’m not good with coding, so I’m not sure what to do.

Help would really be appreciated!

What have you tried so far?
I tried to look up tutorial videos, but I couldn’t find anything that helped me with this particular problem.

Do you have a Wick Editor File that we can see? Optional*
It says new users can’t upload attachments, so sadly, I can’t do that.

if(obj1.hits(obj2)) {} checks if obj1 is touching obj2. You can substitute obj1 for this to check if “this” is touching obj2. Put whatever you need in the curly brackets.

the hits function tells if one object is touching the other object

Can I put an action that I want to be done in the brackets? For example, the command that changes the score? I mean, I think I tried doing that and it didn’t work, but I can try again if you’re willing to help me with how to do it.

Yes you can… that is it purpose.

if(obj1.hits(obj2))
{
// add actions here
}

@Jovanny thanks for the help with the if hits command it is very useful to me

the if hit option is a collision code in my experience.

Usually, i can make an example with a coin collecting game.

So, if i want the coin to be removed or to random position or anything, i use:

if(coin.hits(player)){
this.remove()
}

so, that’s how it works.

You can learn more about it on the reference page.


On the object section you can find the hits() funtion

Alright, thanks :)