I have a problem. Basically, I have 2 clips: a player, controlled by you, with arrow keys.
the other is an ai that follows you around and tries to kill you. I want to have the ai holding a sword that does damage if you get hit by it, and so i make a clip of a sword, inside of the ai clip. the ai is the parent object and the sword is the child.
However, when I type this code on the player’s update script:
if (this.hitTest (sword)) {
project.score -= 10
health.setText (project.score)
}
It simply tells me that “sword is not defined”
I’ve also tried this on the sword, where I write
if (this.hitTest (player)) {
project.score -= 10
health.setText (project.score)
}
and It just says “player is not defined”
If anyone has a solution for this, that would be very helpful.
Thanks
Hey Jakewaxman! Welcome to the Wick community! Can you please send the .wick file if possible?
I did try fixing some stuff, like putting “project.player” instead of just “player” but it hasn’t seemed to work.
Oh… Alright. I’ll see what I can do.
Few things:
[1] hitTest is deprecated, you should use hits instead
[2] hits function used to evaluate child objects is only supported in the test version
[3] After following the first 2 things,
your code should looks like this…
// at player:
if(this.hits(enemy.sword)) { ...
Since the sword is a child clip of your enemy… assuming that your enemy clip is called enemy
Wow thanks! I tried it and it works. Thanks a lot for the help!
I tried doing this… It didn’t work for me. But, it’s alright now. Problem solved!