Next, we’re going to work on the code for the projectiles we shoot.
For this game, there are two directions we want to be able to shoot, to achieve this we need to make a new variable to control this.
Create a new variable, call it “facing”.
Next, create a new function, call it “projectileMotion”.
Inside this function, add the code shown. This will make it so facing is negative if the player is moving left, and positive if the player is moving right.
We want our facing variable to always be updating when playing the game.
To do this, add the code shown. This will make it constantly update our facing variable while playing.
Lastly, let’s complete the code to actually shoot the projectile.
The “set projectile to” block can be found under “Sprites”
Notice how the projectiles fall straight down when the game first starts, why is that?