251,331
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.

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.
117 Comments
yep, you gotta be careful to change the actor type in the "physics" of the bullet to "normal", or it wont allow you to change to the "affected by gravity" option
0
I had the same experience, the bullets were stuck with the ship plus the shipped moved forward when I press the Z key. I double checked everything, the settings were right but no go.
Then I tried changing the value of "yDir" to something other than -1. Tested it, it worked! I changed it back to the original value (-1), now it works as intended. That's weird.
Maybe this is a bug from the engine?
0
I had the same issue. Check the physics properties of the bullet. It should have the gravity switched off.
0
* The slow moving bullets was my mistake (I forgot to change "gently" to "sharply" in the push block.
0
--FIX FOR BULLETS NOT MOVING--
The problem is back in Part 4. It has some confusing wording which leads most to set the physic type of bullets to "Cannot be pushed", and now we are trying to move the bullet with physics.
To fix, change "Actor Type" in the physics tab of Bullet to "Normal". With this changed, the bullet will fire (although really slowly).
The fact that it moves so slow makes me think there is a error somewhere else in the tutorial.
3
So I followed the instructions word for word, but the bullets won't move. Everything else is fine up to this step: the ship moves left and right, and it doesn't go off screen etc. Anyone have an idea what I did wrong?
1





