150,197

Views

Beginner

Level

105

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!

105 Comments

Maxipad
There is no create actor in the Scene>Actors !!!! Only creat actor in next scene
0 4 months, 2 weeks ago
akazizou
hi, anybody can help me?... why is it my bullets are appearing on the left top corner of the screen when I press on "z"? what should i do about this?

0 7 months, 1 week ago
Cr8zycatladys
Our ship only goes left, you cannot control it, and it is being all glitchy to the left. We also cannot shoot bullets, and we still have not found an answer to our question. Anything that could cause that?
.

0 8 months, 1 week ago
0915230240
hi,why my ship can't move is just fly

0 1 year, 1 week ago
ShadyNawas
Clicking "Z" dosen't do anything!
1 1 year, 3 weeks ago
wbhyvong
ship pushed back when shot. collision enemy bullet is stopped.
0 1 year, 2 months ago
l prods
para que no se adieran tienes que ponerle ala bala en la pestaƱa de collisions y te aparecera una casilla que dice type sensor activalo y le pones die in collision
0 1 year, 3 months ago
ConnerPlayz
nvm, i fixed it
-2 1 year, 3 months ago
ConnerPlayz
Ok, so I am having trouble with the bullets colliding with the aliens, when i shoot the aliens they bullets just stick to it and nothing happens, how do i fix this? pls help... Thx
1 1 year, 3 months ago
goodteams
k

-1 1 year, 4 months ago

Sign In to Comment