198,206

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).

http://static.stencyl.com/help/images/bullets_collision_group.png

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.

Click here to go to Part 12.

Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

67 Comments

tmalik
The bullets were not colliding for me too.

I went into Enemy > behavior > Create a new behavior and added an explosion. Saved it. Worked ! Went back in and removed the behavior. Worked.
I know - weird.

0 12 years, 1 month ago
beaunusse
Hello,

I had the same problem but i fixed it.
I went to the properties of my bullet actor and it was on the group of "actor".
I changed it to "bullet" group,.
Maybe some of you will have the same issue.
Hope to be helpfull.

0 12 years, 2 months ago
JuliaBdlt
I found the solution you have to add "kill <last collided actor>" under "kill <self>" in actor-type, I also removed the "enters screen" part, and every things work well.
0 12 years, 3 months ago
JuliaBdlt
same problem, the bullets don't disappear ! please help
0 12 years, 3 months ago
MegaLizardLord
Aaaagh the bullets don't disappear! I read all the comments and checked over and over and the bullets ARE set as bullets and I checked the code a bunch too and it's not working! Please help! :(
0 12 years, 4 months ago
Steerschips
For the bullets not disapearing and not colliding with enemy ship issue, the solutions below are 100% correct but I had another issue that wasnt correct, and that is make sure your bullet actor is in the bullet group, and same for enemy ship (enemies). My bullet actor was in the actors group.
-1 12 years, 8 months ago
DrOmni9885
When the two collides the enemy ship disappears but the bullet doesn't... Help!
0 12 years, 11 months ago
icedvulcanhalo
you need to make bullets "bullets" and you need to add "kill [last collided actor]" to the "Actor-Type" event under bullets
0 13 years, 2 months ago
ladder2976
neither the Bullets or the Enemy ship disappear when they hits each other

1 13 years, 3 months ago
marcstandley
Found the issue:

Instead of using Event type "Enters or Leaves the Screen > Specific Actor," I was using "Actor Type." Actor Type kills all onscreen elements of the specified actor, whereas Specific Actor kills only the instance that leaves the screen.

1 13 years, 5 months ago

" id="comment_form">



Please keep your comments civil and do not spam. Thanks for your cooperation!
Sign In to Comment