Clone hits Clone

My Project1-28-2022_8-20-57.wick (9.8 KB)
I’m trying to make it so that when the bullet clone hits the enemies clone they both get removed but whatever I try doesn’t work and their is not help so I’m asking.

I don’t like posing here I am only doing it for school

I dont know it just throws an error saying that there’s an error at line 57684. maybie try serching for it.

Go inside of the clip, “Vil,” and add in this code in its update script:

for(var a of Bul.clones){
    if(this.hits(a)) {
        a.remove();
        this.remove();
    }
}

This is everything you’ll need to do, afterwards it should work the way you wanted it to
(enemy and bullet getting both removed upon making contact).


I also recommend reading quickly through how this code works here:

Click Me

Bul.clones” returns an array of clones for the bullet object (“Bul”).
for(var a of Bul.clones){...}” sets a statement “for” all values in the array, “Bul.clones,” which you can refer to as “a” in the statement (inside the “{ }”).
The rest is simple… if this (“Vil” or its clone) hits/ touches “a” (a clone from the array), then remove “a” (the bullet clone) and remove this (“Vil” or its clone).


Here’s a cloning tutorial by Luca if your interested (this helped me a lot when I used to know nothing about clones, so I’d recommend it)