251,335

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

RogerWhan
If you're still seeing small images for your actors try setting your scale is set to 1x when you import the frames for the actor (defaults to 4x)
6 10 years, 8 months ago
Kogoll
when press "Z" bullet are create ,but bullets not moving.
Please help my fix this problem...
Thanks for answer.

0 10 years, 9 months ago
TeeMee123
my images came out tiny too
2 10 years, 9 months ago
Bryhannah
Brilliant, Kenops - my bullets were moving but SOOOO SLOW! It was hilarious, but took too long to test, lol. Force = 2000 is perfect.

Did anyone else's images come out teeny tiny? I'm sure I could fix that in photoshop, but I'm going to save all that work for the game I'll create when done with the tutorial. :)

1 10 years, 9 months ago
Ouncechop
Why do i always seem to move back every time i shoot my gun ??? any help
1 10 years, 11 months ago
kenops
Hey, Comrades, If you have problem with not moving bullets, try raising the Bullet Speed number (force).

I raised it to 2000 and now it works fine.

1 11 years, 1 month ago
axe17143
Think it would help greatly just to post the final image for the event blocks of this section.
0 11 years, 3 months ago
TheDarkPhoenix83
I am trying to use this technique to allow my robot guy to shoot. Following the same directions, I assume it would shoot up then I'll adjust that. But, what happens is my robot guy jumps until he leaves the screen at the top. No bullets or anything. This is set in my Robot Events, but I still have no functions. If anyone hasn't quite already, please help.
0 11 years, 7 months ago
thephantombrain
jijigren and I had the same problem. When z was pressed the bullets would appear but not move at all. The problem was that I had the physics of the bullets set to "What kind of actor?" = "Cannot be pushed". Once I changed that to "Normal" and then changed "Affected by gravity?" to "No" the bullets flew just like they were supposed to. Hope that helps someone.

~I'm in heaven when using this program! :) :) :)

3 11 years, 7 months ago
jijigren
I did everything like in the tutorial, but when I test the game the bullet not moves forward. Is there anything I miss or should do? Thanks in advance for any help
-1 11 years, 8 months ago

" id="comment_form">



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