Making a character shoot

2

Stats

8,841 visits, 12,188 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 28 Dec, 2017. Last updated 19 Feb, 2019

Ever wanted to create a Metroid style game, but your player can't shoot correctly? Here's the solution.

Getting started

So you will start by creating your player and his animations, and after you'll go in his animations, image point. You will add a new one and place it on the "gun". Return to the project bar and add an instance variable,number to 0. Just call it "Direction".After you create a bullet and add the the bullet behavior to it.

Input and variable set

Go to your Event Sheet.

Note that I am using the Keyboard plugin, but you can change the input method.

You will take any input and add the condition when right arrow key is pressed, after you will add the action set animation to your walking right one. You'll also add the action Set variable "Direction" to 0.

Do the same with the left but change the animation and the Set variable "Direction" to 180

If you want to aim up or down or in any diagonals, just change the variable value to the angle where he shoot and the animation (don't forget to change the position of the imagepoint 1 to the gun!)

It should looks similar to this:

On Left arrow pressed >

                                            [Player] Set animation to "WalkingLeft"
                                            [Player] Set Direction value to 180

Bullet

You will put an event where when the A key is pressed the player will spawn an other object (the bullet) on the layer of your choice at the image point 1 (the one you put on the gun). By this moment the Direction variable will be useful. You will put an action that is: Set angle of motion of the bullet to Player.Direction (the variable). Here's an example:

On A pressed >

                            [Player] Spawn Bullet on layer 0 at image point 1
                            [Bullet] Set angle of motion to Player.Direction

That will make the bullet go to the left because it is rotated by 180 degrees!

You can change the animations and the variable. If you want him to shoot upwards, just replace the value of the Set Direction event to 270, for example. When he will shoot, the bullet will rotate of 270 degrees, so it will go upwards!

That's it! Now you have the player that shoots correctly and in the right direction without having to add many events!

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • How to collect points in shooting game...

  • when the player bullet hit anything you need, you add the value to instante value of player points and then make the conection for storage on a global variable of points if you whant to record the total points of all nevel for exemple