2. Move the player
You are reading Part 2 of the Space Shooter Tutorial.
- Space Shooter, Part 1
- Space Shooter, Part 2
- Space Shooter, Part 3
- Space Shooter, Part 4
- Space Shooter, Part 5
- Space Shooter, Part 6
- Space Shooter, Part 7
- Space Shooter, Part 8
- Space Shooter, Part 9
- Space Shooter, Part 10
- Space Shooter, Part 11
- Space Shooter, Part 12
- Space Shooter, Part 13
In this chapter, we will learn how to control our spaceship with the arrow buttons.
Click on the "Base Scene (Events)" tab to open the events editor, where we define the rules of the game using conditions and actions. Click on the event icon to add an empty event.
Make the spaceship move with the keyboard
Click "Add Condition." Then there will be a popup menu to select your conditions. We will use the search bar on the top of the view. We will type "Key" and will select "Key Pressed." Then on the right menu, we will type Right to control the Right arrow.
Then, click on Add Action in the same event and select Player since we want to move the Player. On the menu, select Add a force angle and enter the angle as 0, the speed as 400.
If you click the Run button on the upper left, you can try pressing the right arrow and see that the player moves right! Now, we will add other buttons to move the player in every direction.
Please do the same steps or click and copy the condition by CTRL+C/Command+C and paste it by clicking CTRL+V/Command+V.
Then change the pressed key and angle of the force, just like in the screenshot below.
Adding an explanation to your actions
Although our event page seems clear right now, it can get longer and more complex after adding more actions and conditions. Hence, adding comments is useful to explain what these actions do (even if these are quite simple).
To add a comment, we will click on the on the "add a comment" icon on the upper right and type our comment, in this case, "Controls." Then, drag the comment to the top of our actions.
Check that the player movement works
Finally, we can test our game by clicking the "Run" button on the upper left.
It will run the game on your device, and you will be able to control your player by pressing the arrow keys.