Week 1 ยท Day 2
Build a 3D World
Turn yesterday's blank grey window into a real 3D scene โ a ground to stand on, a sun in the sky, a camera to see through, and a player.
โฑ About 45โ60 minutes
๐ฏ Today's mission
Raviv, by the end of today you'll press Play and see a proper 3D world: a green floor,
a glowing box standing on it, lit by sunlight, viewed through your own camera. The first
time your own 3D world appears on screen is a brilliant feeling โ let's get there.
What you'll learn
- The four things every 3D scene needs: a world, a light, a camera, and something to look at
- What a mesh is (any 3D shape you can see)
- How to move and rotate things using position and the arrows
- How to give an object a colour
๐ก Before you start
Open the My First Game project you made yesterday (double-click your Godot
shortcut, then click the project). Everything today builds on it.
Part 1 โ A fresh 3D scene
-
Start a new scene
Top menu: Scene โ New Scene. You'll see options for the type of root node.
-
Choose "3D Scene"
Click 3D Scene. A node called Node3D appears, and the
middle of the screen switches to a 3D view with a grid floor and coloured arrows. This is
your empty world.
-
Rename it and save
Double-click Node3D in the Scene panel and rename it World.
Press Ctrl + S and save it as world.tscn.
๐ก Getting around the 3D view
Hold the middle mouse button (the scroll wheel) and move the mouse to orbit
the camera. Scroll to zoom. Hold Shift + middle button to slide
sideways. Have a quick play โ you can't break anything by looking around.
Part 2 โ Add the ground
-
Add a shape node
Click World, then + Add Child Node. Search for
MeshInstance3D and create it. A MeshInstance3D is "a slot for
a 3D shape" โ right now the slot is empty, so nothing shows yet.
-
Put a flat shape in the slot
With the MeshInstance3D selected, look at the Inspector on the right. Find
Mesh, click the box next to it that says <empty>, and choose
New PlaneMesh. A flat square appears โ that's your ground.
-
Make it bigger
Click the word PlaneMesh that just appeared in the Inspector to open its
settings. Set Size to 20 ร 20. Now it's a proper
field, not a tile. Rename this node Ground.
Part 3 โ Add the sun and a player
-
Add sunlight
Select World โ + Add Child Node โ
DirectionalLight3D. This is the sun. To stop it shining straight down flat,
select it and in the Inspector set Rotation X to about -45.
-
Add the player block
Add another child of World: a MeshInstance3D. Give it a
New BoxMesh (same way as the plane). Rename it Player.
-
Lift the box onto the ground
The box is half-buried in the floor. With Player selected, set its
Position Y to 0.5 in the Inspector. Now it sits neatly on top.
๐ก X, Y and Z โ the three directions
Everything in 3D has a position made of three numbers: X is left/right,
Y is up/down, and Z is forward/back. The box was sunk
halfway because the floor sits at Y = 0 and the box is 1 tall, so its middle needed to go up
by 0.5. You'll think in X/Y/Z constantly from now on.
Part 4 โ Add a camera and press Play
-
Add the camera
Add one more child of World: a Camera3D. This is the eye your
game looks through. Right now it's at the centre looking forward, which isn't a great view.
-
Pull the camera back and up
Select Camera3D and in the Inspector set Position to
X 0, Y 4, Z 8. Then set Rotation X
to about -25 so it tilts down towards the box.
-
Run it
Press F5. Godot asks for a main scene the first time for this scene โ pick
Select Current. Your 3D world opens: a green-grey floor, a box standing on
it, lit from the side. ๐
โ
You did it!
That box on a sunlit field is the seed of your whole game. Everything โ the trees, monsters,
villages โ gets added to a world built exactly like this one.
Understand it โ the four ingredients
Every 3D scene you'll ever build needs the same four kinds of thing. You just added all four:
1. A world to hold everything โ your World (a Node3D). A Node3D
is simply "anything that has a position in 3D space". It's the tray everything else sits on.
2. Something to see โ your Ground and Player
(MeshInstance3D). A mesh is any 3D shape: a box, a sphere, a whole castle.
If you can see it, it's a mesh.
3. Light โ your DirectionalLight3D. Without light, a 3D world is
pitch black, exactly like a real room with the curtains shut. "Directional" light acts like
the sun: parallel rays coming from one direction.
4. A camera โ your Camera3D. The world might exist, but you only
see the slice the camera is pointed at. Move the camera, change what the player sees.
๐ก The logic to remember
World + Mesh + Light + Camera = a scene you can see. If you ever press Play and get a black
screen, run through the list: is there a light? is the camera pointing the right way?
Nine times out of ten that's the problem.
Play around โ level up ๐ฎ
๐ข Level 1 โ Easy
Give your player some colour. Select Player โ in the Inspector find
Material Override โ New StandardMaterial3D โ click it โ
set Albedo (that just means "base colour") to your favourite colour. Run it.
๐ก Level 2 โ Medium
Add a second box somewhere on the field as an obstacle. Give it a different colour and a
different Position X and Z so it sits apart from the player. Now your world has scenery.
๐ด Level 3 โ Spicy
Move the Camera3D to a bird's-eye view: try Position Y 12 and
Rotation X -90 (straight down). How does the whole game feel different
from above? Lots of strategy games use exactly this camera.
๐ฌ Experiment: turn off the sun
Select the DirectionalLight3D and untick Visible at the top
of the Inspector (or just delete it). Run the game โ everything goes dark! Put it back. Now you
can feel why every scene needs a light.
If something went wrong
"Everything is black when I press Play." You're missing a light, or the
light is rotated to point away. Add a DirectionalLight3D to World and set its Rotation X to
about -45.
"I press Play and see nothing / a tiny dot." The camera is probably inside
the floor or facing the wrong way. Re-check Camera3D Position (0, 4, 8) and Rotation X (-25).
"My box is sunk into the floor." Set the Player's Position Y to 0.5 so its
middle sits half a box above the ground.
"I added MeshInstance3D but nothing showed up." The Mesh slot is still empty.
Select the node and give it a New PlaneMesh or New BoxMesh in the Inspector.
Tomorrow that box stops standing still โ
you'll drive it around with the keyboard. ๐น๏ธ