Stage 5 of 11
The camera
By the end
- A camera with no perspective, at pixel art's 2:1 angle, following a box on stage 4's spring.
- The game running for the first time.
- A feel for the spring's three numbers, from changing them while it runs.
The idea
Three things make this camera, and stage 6 adds a fourth.
- No perspective. It's orthographic: far things aren't drawn smaller, and lines that are parallel in the world stay parallel on screen. How much it shows is set by how many metres of the world fit between the bottom of the screen and the top (
view_height), not by how far away it stands. - A fixed angle: turned 45° round and tilted 30° down. At 30° down a square floor tile is drawn as a diamond exactly twice as wide as it is tall (sin 30° = 0.5). That's pixel art's classic "2:1": the tile's edges climb one pixel for every two across, which pixels draw cleanly. True isometric is 35.26° down, and its edges don't land on pixels as neatly.
- It follows on a spring: stage 4's
SecondOrder, on the position of what it follows.
Why it's like this
The angle was measured against t3ssel8r's game view in his video: his tiles repeat every 197 × 99 pixels, and this project's every 36 × 18 at the script's default zoom. Both are 2:1.
The script and its node
- Create
camera/iso_camera.gd. - In
main.tscn, add a Camera3D underMainand name itCamera. Dragiso_camera.gdfrom the FileSystem dock onto it in the Scene dock: that attaches the script, and a small script icon shows by the node. - It needs something to follow, and Leela isn't here yet. Add a MeshInstance3D under
Mainand name itStandIn. In the Inspector set Mesh to New → BoxMesh, and Transform → Position to 0, 0.5, 0 (only its y needs typing). That's a 1 m box sitting on the floor. You'll delete it in stage 7. - Select
Camera. The Inspector starts with a Camera Preview picture. Under it is a heading with the script's name,iso_camera.gd, and under that the script's exported values:
| Property | Value | Why |
|---|---|---|
| Target | StandIn: press Assign..., click StandIn in the Select a Node dialog, then OK | The node it follows. |
| View Height | 3.5 | Metres of the world from the bottom of the screen to the top. |
Leave the rest: Pitch −30, Yaw 45, Distance 30, Snap on, and under Follow, Frequency 1, Damping 1, Response 0.
Target is a Node3D, so WorldEnvironment, which isn't one, is missing from it.Why 3.5
The script's own default is 14, a long way out. The owner chose 7, then asked to zoom in twice the same day: 5, then 3.5.
In the editor's 3D view the camera still sits at the origin, looking along the floor. That's as it should be. The script isn't a @tool script, so it only places the camera when the game runs.
How it works
Its numbers. Each @export is a property you just saw in the Inspector:
@export var target: Node3D
@export_range(-89.0, -5.0) var pitch := -30.0 ## degrees down: -30 is pixel art's 2:1, true isometric -35.26
@export var yaw := 45.0 ## degrees round
@export var view_height := 14.0 ## m of the world from the bottom of the screen to the top
@export var distance := 30.0 ## m back (orthographic: only so nothing's behind it; look/environment.tres's depth fog is set for 30)
@export var snap := true ## to the picture's pixels (off: plain following, and the pixels crawl)When the game starts, it switches to orthographic and makes its follower, starting where the target is:
func _ready() -> void:
projection = PROJECTION_ORTHOGONAL
_shown = view_height
_home_yaw = yaw
_home_height = view_height
var at := _target_position()
_follow = SecondOrder.new(frequency, damping, response, at)
_place(at)Every frame it feeds the target's position through the spring and puts itself where that comes out. The first line hands the spring its three numbers again every frame, which is what lets you change them while the game runs:
func _process(delta: float) -> void:
_follow.set_parameters(frequency, damping, response) # (so they can be tuned while it runs)
# ...
_place(_follow.update(delta, _target_position()))And _place() begins like this:
func _place(at: Vector3) -> void:
size = _shown
far = distance + 100.0
global_basis = Basis.from_euler(Vector3(deg_to_rad(pitch), deg_to_rad(yaw), 0.0))
var b := global_basis
var where := at + b.z * distance # (it looks along -Z)sizeis an orthographic camera's zoom: the metres from the bottom of the view to the top.global_basisis which way it faces, built from the two angles.where: a camera looks along its own −Z, sob.zpoints out of its back. It standsdistanceback that way from the point it's looking at.
With no perspective, distance changes nothing you can see, with one exception: fog is measured from the camera. That's why stage 3's fog numbers were set for 30. The rest of _place() is the pixel snapping, which waits for stage 6.
Checkpoint
Run the project (F5). The game shows in the editor's Game workspace, which pops out as a window of its own unless you've told it not to (Before you start says how).
- You're looking down on the floor at an angle, and its tiles are diamonds twice as wide as tall.
- The white box is in the middle of the picture, with a long shadow to its right.
- The ground at the top of the picture fades into violet.
If not:
- The view is flat along the floor, with a horizon: the script isn't on the
Cameranode. - An error naming
SecondOrder: stage 4's script isn't atproc/second_order.gd, or its first line isn'tclass_name SecondOrder. - Everything is tiny: View Height is still 14.
Try it: the three numbers
This is the best place in the project to get the feel of f, z and r, because the thing being followed moves in clean jumps.
- With the game running, press Remote at the top of the Scene dock, open
Mainand clickStandIn. - In the Inspector change its Position's x from 0 to 4. The box jumps 4 m, and the camera glides after it.
- Click
Camera, open Follow, set a row of this table, and move the box 4 m again:
| Frequency | Damping | Response | What the camera does (measured) |
|---|---|---|---|
| 1 | 1 | 0 | The project's values. Halfway in a quarter of a second, there in about a second, no overshoot. |
| 1 | 0.3 | 0 | Swings 1.5 m past the box and back, settling in about 1.8 s. |
| 1 | 1 | −1 | Backs off 0.8 m the wrong way first, then goes. Anticipation. |
| 1 | 1 | 2 | Leaps ahead, half a metre too far, and is there sooner. |
| 3 | 1 | 0 | There in a third of a second. |
Stop the game and the camera has its saved numbers again.
Checkpoint: before stage 6
- The game is stopped, so
StandInis back at 0, 0.5, 0 and the camera's Follow numbers are 1, 1, 0 again. main.tscnis saved, withCameraandStandInunderMain.Camerahasiso_camera.gdon it, TargetStandInand View Height 3.5.