Scene setup
This is a guide to making a 3-dimensional game in Godot. If you are unfamiliar with Godot, check out the Godot basics doc and the 3D fundmentals doc.
We’ll be making a game in which the player defends an objective against constantly spawning waves of enemies, with both a lose and win condition. Designed to act as a foundation for your own ideas, allowing for easy expansion and polish.
Making the project
Set up a Basic 3D project, using the Forward+ Renderer. Create a Node3D as the root, and call it ‘World’
Working with the 3D Viewport
When working with 2D Space, we work on two axes, X and Y. When working in a 3D space, we add a third, Z. In Godot, Y represents up and down, while X and Y represent the two horizontal axes.
While mousing over the 3D game viewport, holding right-click will allow you to fly around the viewport using WASD. You can use the scroll wheel to control your speed. While not holding right-click you can use the scroll wheel to zoom in and out.
Now that you know the basics, let’s get into making our game!
Creating a first-person controller
Let’s set up a basic character controller. Thankfully, Godot makes this easy for us and actually has a template script that’ll let us move around.
Scene Setup
First, let’s give ourselves something to stand on.
- Create a Node3D and name it ‘World’ or ‘Level’ this’ll be the root of our whole scene.
- Create a StaticBody3D and give it two child nodes, a MeshInstance3D and a CollisionShape3D. The mesh provides visuals for our floor, while the collisionShape is what we actually stand on.
- Select the MeshInstance3D and over on the right, in the inspector, assign its Mesh property to be a PlaneMesh
- Select the CollisionShape3D and set its ‘Shape’ property to a new BoxShape3D
- Select CollisionShape3D in the scene tree and use the orange dots in the viewport to shape the BoxShape3D to the same shape and size as the plane. Although it’s good to leave it a little thicker than the plane, to stop us from falling through.
- Click on the StaticBody3D and find the Transform over on the right. Increase any of the Scale values to something like 20. They’ll all increase as they’re ‘linked’ (Denoted by the chain on the right)
Great! Now our player has something to stand on. Let’s add our Character.
Adding the Character
- Create a CharacterBody3D as a child of our root world node. right-click on it, and save it as a new scene. This allows us to easily modify our player. Name it ‘Player’ or ‘Character’
- Find the newly created scene in the file explorer, or click on the “scene” icon, to open our scene.
- Give it a Camera3D and a CollisionShape3D as children. Given the collisionShape a capsule shape using the inspector. The CollisionShape is what’ll allow us to collide with the floor.
- right-click on the CharacterBody3D and assign a script, leave everything as default and hit load. This is because we’re using the script Godot provides for us. For now we won’t be messing with this, you can click 3D at the top to return to the scene view.
- Let’s click on the Camera3D over on the left, and use the green arrow in the viewport to move it on the Y-axis to wherever you think the ‘eyes’ of your character should be, based on the capsule.
- Make sure you save the scene, using CTRL + S or using the File menu in the top left.
- Let’s go back to our main scene now, using the tab with the name you used for your ‘World’ Scene. You’ll probably notice that the player is halfway in the floor, which is not ideal. Just click on the root CharacterBody3D Node and move to up on the Y-Axis
- As a final touch, let’s add a DirectionalLight3D and rotate it to face downwards so that we can see!
Great! Let’s test our game! Hit the Run Project Button and try moving around! You’ll probably notice two things:
- We can’t look around
- The default controls use the arrow keys to move, when WASD is generally standard.
Don’t worry, we’ll fix these issues shortly.
Some things to try
-
Try deleting the collision shape from the ground or the player, what happens?
-
Open up the Script for the character movement, try changing the speed up or down, what happens?
Checklist
- I have something to stand on
- I can move around using the arrow keys
- I’m ready to make a game!