[SOLVED] Lasers won't destroy enemyships

Student’s game lasers not destroying the ships when collided with.
Tried changing code to false instead of 0 but no luck.
Editing link: PlayCanvas | HTML5 Game Engine

Hi @Ashley_Solano! Which script and entities we need to look at?

I found the trigger script. There is a wrong letter s at line 16. On line 17 and 18 the 0 need to be false. Be aware that a trigger cannot have a rigidbody.

@Ashley_Solano I don’t know if this will be a long term issue or not but one of the things that I have noticed looking at the scripts for these class projects is the following. I see that the enemy ships are getting instantiated and then eventually once hit they are disabled. But they are never destroyed. I am wondering if eventually memory will be consumed and will cause an issue. @Albertos may have some thoughts.

Good point @Tirk182, maybe destroying the entity is better in this case.

result.destroy();
1 Like

Thank you for the advice, I have changed to destroy. I tried a few more things with the enemy template but still not making them disappear when the playerlaser collides with it

1 Like

gahhh! lol thank you! fixed! :nerd_face:

1 Like

By the way, you need to destroy the entity itself too for the same reason as @Tirk182 mentoined.

Where would we do that?

You now use this.entity.enabled = false;, that should be this.entity.destroy();.

I would do that after you destroy the result entity.

1 Like

thanks so much!

@Ashley_Solano @Albertos is correct in his thinking. So when you instantiate an object you are actually creating a place in memory to hold it. When destroyed using destroy() you will free the memory that the object was occupying. This is good practice. Another thing to note is when a enemy goes by you and you do not hit it. It will still be alive in memory even if you set enabled=false;. So in the long term play you will keep allocating memory for enemies which could give your users an error over time.

One suggestion for the enemies that get past the player would be to add users position to the instantiation code so when the enemy passes the user position it destroys itself. There are other ideas on how to do this as well like creating an off screen wall that has a collision that fires destroy on the ship that got past. Hope this helps

1 Like