198,200
Views
Beginner
Level
67
Comments
Crash Course 2: Invaders - Part 11
by Hectate (Updated on 2015-05-02)
Part 11: Destroying Bullets
If we didn't do something to remove Bullets from the game correctly, it might eventually affect performance (assuming the player shoots as much as we expect them to). Lets set something up to destroy our Bullets at a couple of key times. Switch to your Bullet actor type's Event tab.
Step 78: Add an Actor of Type Collision Event (click + Add Event button on the left, then select the Event, as shown).

Step 79: Set the Actor Type to Enemy Ship, then drag over a Kill [Self] block from the Palette (under Actor -> Properties).

Now each Bullet Actor will be destroyed when it collides with an Enemy Ship.
Step 80: Next, to ensure our Bullets are also destroyed when they leave the screen, we need to add an Actor Event, when a Specific Actor Enters or Leaves the Screen, as shown:

Step 81: Change the dropdowns on the Event block that appears from enters to exits, and from scene to screen, then drag over a Kill [Self] block (Actor -> Properties in the Palette).

If you were to test your game now, you would probably notice that the bullets don't get destroyed when they collide with the enemies. The reason for this is that the collision group for the bullets is not set to collide with the enemies.
Step 82: Select the Bullet actor type's Properties tab, and make sure that the Group is set to Bullets. Then click "Edit Groups". The Collision Group section of Game Settings will open up. Make sure that the "Bullets" group is highlighted to the right and then click the "Enemies" group so it turns green (as in the image below).

Save your game and test it; now the bullets should be disappearing if they collide with the enemies. Next, it’s time to set up what actually happens when Bullets collide with the Enemy Ships, instead of just removing the bullets from the game.
67 Comments
Typo in line 2: "Add an Actor of Type Collision Event" should be: "Add an EVENT of Type Collision" (without the "event" at the end).
Great software and great tutorial by the way, thanks, I'm really getting the hang of it. And enjoying it :)
0
I am having the same issue as an earlier commenter where my bullets to disappear when they hit an enemy ship. My bullets and enemies are both set as the correct groups and i have them set to collide with each other, any other suggestions?
0
I found that my problem with the non collision detection is that my bullet group was not set as bullets, but instead as actors...
I hope that helped for you!
3
I cant get my bullets to actually collide with the enemy, im sure ive missed something out but ive looked through this page a few times and cant figure out what the problem is.
0
edit: make bullet always active seemed to have been messing up the collision...So I added a continuous collision detection block and that worked.
1
@talmore
That's strange, I did what you said and it worked for me also...Can anyone tell me why you must make the bullet always active in the when created event?
0
My game was laggy. I found that the bullet was not killing itself when leaving the screen by using a print command. Looking at other code I found that if you add a creation event and add a make self always active it worked...
0





