251,341

Views

Beginner

Level

117

Comments

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!

117 Comments

Heymi
i did as shown above but my bullets aren't firing, what should i do?? :(
0 12 years, 7 months ago
jkuros
I am also trying to fire the bullets but they stay still, what did you figure out? By your quick reply to figuring it out I feel like I'm missing something obvious...

I have when action 1 is pressed,
create bullet at (x: x of self y: y of self) at Middle
push Last Created Actor sharply towards xdir:0 and ydir: -1 at 40 force

0 12 years, 7 months ago
Incarnin
Never mind, I figured it out...
0 12 years, 8 months ago
Incarnin
I fire my bullets but they stay still?
0 12 years, 8 months ago
soligboemmanuel
my bullet move up and my was also moving up with my bullet, what did i do wrong
0 12 years, 8 months ago
adtreborn
so my ship flys off and my bullets stay in place......

1 12 years, 8 months ago
softsound
If your bullets are only firing on part of the screen -

go to the ship's keyboard event
in the create bullet at x.... make this x-center and y-center of self
or
x(on screen)

-1 12 years, 9 months ago
katkin
Ok - I didn't see it in comments BUT - if your bullets are not SPAWNING...

Make sure the above is done under SHIP events, NOT under bullet events...

0 12 years, 10 months ago
jengbrand
Another thing to look for if your bullets aren't firing...the 'push' block should come from Scene > Actors not Scene > Game Flow (which has 'in the next scene' at the end of the block).
0 12 years, 10 months ago
Jonathan916
so my ship is staying to the left what did I do wrong it fires lasers and such but it is staying to the left.
1 12 years, 10 months ago

" id="comment_form">



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