As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!







Crash Course 2: Invaders - Part 10

by Hectate (Updated on 2015-05-02)

Part 10: Enabling Our Ship to Fire Bullets

Step 73: Our next Event will create a Bullet Actor and set it in motion when the player presses a keyboard key. Click the + Add Event button, mouse over Input, and select Keyboard. Remember, we should already be in the Ship's events screen to create this.

Tip: To make sure your bullets fire properly, make sure you remembered to set their Actor Type in the Physics tab to Normal. We covered this in Part 4, Step 26

Step 74: On the block that appears, set the control dropdown to action 1, as shown.

Step 75: Now we need to grab two blocks, one that creates our Bullet Actor and another that sends it on its way.

The first is under Scene -> Actors in the Palette. The second is under Actor -> Motion.

Select the Bullet Actor Type by clicking on the dropdown on the create Actor Type block, and in the blue push [Actor] block, change the [Self] field to [last created actor] and [gently] to [sharply]. Snap them together into the Event block, as shown.

Step 76: Next, we need to set where the Bullet is created and the direction it should travel in. For the x and y values, set them to x of self and y of self, which is the current position of the Ship on screen. This block is in Actor > Position. Alternatively, cClick on each dropdown (for x and y) to choose the x of self block from the Actor category in the Block Picker. Then switch the [x] to [y] in the second block, as shown.

Step 77: From here, we set the direction and force the Bullet Actor will launch at in the push [Last Created Actor] block. Set xDir to 0 (we only want the Ship to shoot bullets toward the Enemy Ships, which is up, not horizontally) and yDir to -1. Remember, that “up” on a computer screen is in the negative y direction. Lastly, set force to 40.

Test the game again, and press Action 1 to shoot your bullets (should be Z by default).

We now need to ensure our Bullet Actors are destroyed when they collide with the Enemy Ships and when they leave the screen.

Let’s continue to Part 11.

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!


Chris24XD nvaders-fixed-solution <-- fixed solution
-1 3 years, 10 months ago
Chris24XD 2
Use this image for fixing events: zMucG5n/original/s7KyLW.png
(l fixed this)

1 4 years, 1 month ago
Chris24XD 2
For that had problem with the bullet listen here:
At ''Create (chosen Bullet) at ( x: change the ''Last Created Actor'' with Ship and ( y: change the ''Last Created Actor'' with Ship
Make this:
Create [ Bullet ] at ( x: [ [ x ] of [ Ship ] y: [y] of [ Ship ] ] ) at [ Front ]
If this helped you, thank you from me.

1 4 years, 2 months ago
Hi,I have a problem with my bullet actor. When i press "z" my bullets are appearing behind of me.I would really appreciate for your help
1 4 years, 3 months ago
Solution to people with Peruvius' problem, few messages earlier:
(probably the same issue with other people having the bullets spawn at top-left corner)

Don't use Actors > Motion > x/y-speed of Self

This is indeed the SPEED of your ship. So if you are stationary when you shoot, the bullet will spawn on the top-left corner of the screen (0,0).
If you are moving to the right, you have a speed of 20, so it will spawn at (20,0). This is still very close to the top-left corner.

The correct item is to use Actors > Position > x/y of Self.

Or if you want to use the selection menu, drag the old "x-speed of self" -block to trash, click the empty dropdown, and select Actor > Basics > x of Actor. Afterwards, change the "Actor" to "Self". Do the same for block (now also remember to change x to y).

1 4 years, 10 months ago
1 4 years, 11 months ago
Low Five
0 5 years, 2 days ago
What key do you have to press to make the bullet spawn? I can't spawn the bullet.
2 5 years, 5 months ago
I can get the bullets to spawn, but they appear in the upper left corner of the screen, regardless of where the ship is on screen. I'm fairly sure I have the parameters set right [create bullets at (x: x-speed of ship y: y-speed of ship) at front] over [push last created actor sharply towards (x-dir:0 y-dir -1) at 40 force].

Hopefully I conveyed this as clearly as I could, and thank you for your help.

2 5 years, 6 months ago
Hi... ummm so my bullets arent even making it to the enemies. They stop about half way up the screen. I have checked everything 1000 times and cant find anything wrong with them. what should i do or where did i go wrong?
2 5 years, 11 months ago

Sign In to Comment