251,336

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

RickDarkmoor
For Raithology, the top left corner of the screen is 0, 0 (x,y) so to the right is positive, and down is positive y. Since your bullet starts at the bottom (for example, around y-position 420) then as it goes up the y position gets lower. That is why you have to subtract. If the bullet went from y-pos 420 to y-pos 400, it would be closer to the top of the screen.
0 13 years, 4 months ago
artmonkey79
thanks for the correction made about changing the gravity to normal on the bullets. I was pulling my hair out till i scrolled down to the comments.
0 13 years, 5 months ago
Lingesh7
http://www.youtube.com/watch?v=0Kka Q52aR_s
0 13 years, 5 months ago
Lingesh7
really sorry heres d link http://www.youtube.com/watch?v=0Kka Q52aR_s
0 13 years, 5 months ago
Lingesh7
sry http://www.youtube.com/watch?v=_eAy QGfSJDI
0 13 years, 5 months ago
Lingesh7
can sum1 pls help me i did exactly wat d crash course said but sumthing is wrng heres a vid
http://www.youtube.com/watch?v=_eAy QGfSJDI

0 13 years, 5 months ago
Daleman
To clarify on zebbe94's comment:

To fix the push issue we seem to be having, go to the Physics Tab for the Bullet Actor and select Normal. Before I did this, my bullets would fire and stay in the same position they were created in, "za warudo" style. After changing the Physics to Normal, the bullets moved upward and stopped abruptly at the enemies.

1 13 years, 6 months ago
raithology
I've just one question. in the technical graph on the x axis left to right is positive. so is that the same in scripting? also why then is up negative Y?
1 13 years, 6 months ago
zebbe94
If the pushing isn't working, make sure that in the physics tap you have selected "normal", I had it on "cannot be pushed" for some reason.
If you don't use "push" you may have problems with bullet collision later in this crash course.

1 13 years, 7 months ago
TheLengua
If push isn't working, try using (set x-speed to 40 for last created actor).
-1 13 years, 7 months ago

" id="comment_form">



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