198,208
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
I was having the issue of my bullets not colliding with the enemies as well.
My solution was to set the collision groups within the Settings > Groups menu for each actor. Turned out I hadn't set a "Collides with" group for Bullets, which should be Enemies (and Enemies should collide with Bullets). Setting these collision groups within that menu worked like a charm.
Now I have an issue of all on-screen bullets disappearing when the first bullets fired leave the screen. Has anyone else had this problem? Solution?
1
I had the problem where the bullets were not colliding with the enemy ships as well. Turns out the solution was quite simple.
SOLUTION:
Although you may THINK that your collision groups are set up properly, if you did not press "okay" [and closed it with "x" instead] it will not save and apply the collision groups properly. However, if you open the menu again, it will LOOK like the collision groups are set up just fine.
TL;DR: Press okay to save and apply changes.
1
I had the same problem, couldn't make Bullets colliding with enemies...
in Groups collision set Bullets to collide with enemies, and enemies collide with bullets... that solved my problem...
Hope that was useful...
1
I don't know if this will help but here is what I did to make it work. I basically took the above code that was supposed to be in the "Events" tab within the Bullet actor itself and created a separate behavior for it. So instead of adding the events directly into the Bullet I made the exact same code into a behavior and attached it. My only difference is I used recycle instead of kill but same thing :)
0
Thank you to epicjoker and wisemangaming. I don't know if I missed a line in the tutorial or if the tutorial is full of typos (okay it's a little of both) but setting my bullets to being bullets helped.
0
Alright it took me to the next part to figure out what I did wrong here.. From the dashboard > Enemy ship > Collision, at the bottom right of the page it says edit groups... ( I don't remember how I got there originally when I created the groups) Edit groups on the far right of this page it has your groups click bullets and make sure enemies is green then click "Enemies" and make sure bullet is green..
0
TIP: If your bullets do not disappear when they hit an enemy ship go to the actor "Bullet" hit the Properties tab go down to group and change it from actor to bullet.
1
I did what the tutorial says, but my bullets go straight through the enemy. I tried "make self always active" but it still doesn't work.
0





