198,209

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

Osman2001
I tried everything... but the bullets won't collide! Can someone help me?
2 11 years, 2 weeks ago
halimsantoso
how to change from word actors to self?
1 11 years, 3 months ago
MathiyalaganColombo
pls check the collision box of actor
0 11 years, 7 months ago
Ricin N Castor
If your bullets are not colliding here are some things I checked to correct it.
1st click enemy ship tab then properties and make sure that enemies is the group
2nd click edit groups and on the right side of the next screen click your enemies group and make sure that bullets is the only tab thats green
3rd click bullets on the right side of the screen and make sure enemies is the only tab that is green then click ok
4th click bullets tab at top of screen and make sure bullets is the group not actors
save and test.....if this doesnt work I dont know what happened good luck

3 11 years, 8 months ago
niall tombson
I tried and tried and tried
The bullets don't hit the enemies
Y ??
I checked everything
Can someone help me ?

2 11 years, 10 months ago
lize
why step 76 ??
i think step 75 is enough

0 11 years, 10 months ago
FBarajas21
at least I believe it will worked it this type of game,
you can also add the "kill last collided actor" right after "if health points<=0", I would think that would worked much better. and even on games were the enemies are moving. correct me if I am wrong, I am new to this.

0 12 years, 3 weeks ago
FBarajas21
To fix the problem where the last bullet that collides with the enemy ship.
go to "Enemy Ship"
then to "Events"
then "updated", the event that was created
after that add "kill last collided actor" before "killed self"*

*this will only work in this type of games where the enemies aren't moving.

1 12 years, 3 weeks ago
LTGamer
Mine seemed to leave the screen before I added that last part of code. Did I still need to use it then?
0 12 years, 3 weeks ago
Hofaware
If you have the same problem like me (and everyone else in the comment section) that your bullets don't collide with the enemy ships, make sure to ceck the collision stettings of the group where the bullet actor-type is in. For that group, the collision with the group "Enemies" should be turned on.
0 12 years, 1 month ago

" id="comment_form">



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