Stage 11 of 11
Going further
By the end
- The repo's test layout: stairs to a platform, a ramp to a ledge, three steps and a pillar.
- How she gets up a step, why she falls off an edge on purpose, and where her jump's shape comes from.
- The camera's turn, zoom and reset.
- A list of what's in the repo that these posts only name.
The main path is done. These are in the project too, told more briefly. Nothing here needs a new idea, only more of the same script.
More to walk on
The floor is a Block. The kit has two more pieces worth having. Create level/pieces/slope.gd and level/pieces/stairs.gd as the repo's files, and Slope and Stairs turn up in Add Child Node... beside Block. (rail.gd is in the repo's kit as well; its scene has no rail.)
The repo's test layout, all under Level. Sizes and positions are in metres, and Look stays dark:
| Name | Piece | Position | Its numbers |
|---|---|---|---|
Stairs | Stairs | 6, 0, 0 | Run 3, Rise 1.2, Width 3, Steps 6 |
Platform | Block | 6, 0.6, −6 | Size 6, 1.2, 6 |
Ramp | Slope | −6, 0, 1 | Run 4 |
Ledge | Block | −6, 0.5, −4.5 | Size 3, 1, 3 |
Step1 | Block | 0, 0.125, −3 | Size 1.5, 0.25, 1.5 |
Step2 | Block | 0, 0.25, −5 | Size 1.5, 0.5, 1.5 |
Step3 | Block | 0, 0.375, −7 | Size 1.5, 0.75, 1.5 |
Pillar | Block | −10, 1.5, −8 | Size 2, 3, 2 |
A Slope and a Stairs start at their node and run away from you along −Z, climbing Rise. So the stairs lead up onto the platform and the ramp onto the ledge.
How a new piece arrives. Each comes in at the middle of the world, named after its kind, with the script's own numbers:
- A new Stairs goes down. Its Rise starts at −1.2 (with Run 3.6, Width 4 and Steps 8), so it's under the floor, out of sight, until its Rise is above 0.
- A new Block is 2 × 1 × 2, with its middle at its node. That's why the platform's y is 0.6: half its height, so it stands on the floor.
- Rename the ones the table names differently (F2, with the node selected). A Block arrives as
Block.
Level, given its numbers and moved to its place. The 3D view was drawn back with the mouse wheel first, so there's room to see them land.Stairs are two things at once. The steps you see are solid, on layer 1. Over them lies a hidden smooth slope on layer 13. A body that only glides, like the stand-in this project started with, has layer 13 in its mask and slides up the slope. Leela hasn't: her feet find the real steps and carry her up them.
It's a test bed. The owner arranges the playground themselves. Treat this layout as something to walk on, not as a level.
Checkpoint
(measured in the rebuilt project, steering her as the stick would):
- The stairs: she walks up all six steps onto the platform in about two seconds, never with both feet off the ground.
- The ramp: up it and onto the ledge.
- The three steps: up the 0.25 m, the 0.5 m and the 0.75 m one in turn, and off the far end.
- Off an edge: walked off the platform or the ledge, she's in the air for 0.4 s, lands, and walks on.
Steps and edges
How does a body held up by springs get up a step? Three things in robot.gd, each a few lines.
She reads the ground ahead. rest, the height her legs hold her hips at, was "the ground's height plus her leg". The ground's height, _terrain, is the highest of up to four rays:
var spots := [_base, _base + _flat(v) * 0.15]
var way := _flat(want) if want.length() > 0.1 else _flat(v)
if way.length() > 0.2:
spots.append(_base + way.normalized() * 0.3)
spots.append(_base + way.normalized() * (0.3 + 0.2 * _flat(v).length()))
var ground := -INF
var walled := false
for spot: Vector3 in spots:
var query := PhysicsRayQueryParameters3D.create(Vector3(spot.x, top, spot.z), Vector3(spot.x, top - 2.5, spot.z), 1)
query.hit_from_inside = true
var hit := space.intersect_ray(query)
if hit and hit.normal != Vector3.ZERO:
ground = maxf(ground, hit.position.y)
# ...
_terrain = ground if not _placed else lerpf(_terrain, ground, 1.0 - exp(-dt / 0.08))One ray is under her middle, one a little ahead by her speed, and two further ahead the way she's steered. So she rises to a step before she gets there, goes over it on long legs with her feet following, and doesn't sink again until her middle's off the far side. The last line smooths the change, so she rises steadily and doesn't jerk.
The rays look down from top, which is one step's height (STEP_UP, 0.35 m) above her highest foot. Anything taller than that isn't ground to her. It's a wall.
Her feet look for room. _room() and _clear() are why her feet don't end up half inside a step. A landing spot needs ground no lower than her leg can reach, the same ground under her toes, and nothing standing higher within 0.12 m beside or behind it. Without room the spot is pulled back, then a little inwards (the list PULLS), never onto her other foot. If there's still no room, the foot comes back down where it was.
Over an edge she falls on purpose. _over_drop() is true once the ground under her middle is more than a step below her feet, she's leant 0.2 m out past them, and she isn't heading back. Then _fall() lets go with both feet. She falls at her own weight, legs reaching down, and lands as from a jump.
Why it's like this
Each rule is there because of something the owner saw. A foot once stepped off the platform onto the floor far below, and the leg was drawn straight through the platform to reach it. Feet were planted 1 to 3 cm from a step's side, with the shin inside it. And the first way of falling, at a jump's heavier gravity with her legs tucked up, the owner found "really weird".
The jump
Space works since stage 10. What's worth knowing is where its shape comes from: the model's own Jump clip. How deep she crouches, how high she goes and when her feet leave the ground are all read from the clip once, at the start (_read_jump()), and the physics is then made to keep to it.
jump() only starts a clock:
func jump() -> void:
if airborne or crouching or _jump_length <= 0.0:
return
for foot in feet:
if not foot.gone and foot.planted:
crouching = true
jump_clock = 0.0
_heavy = true
returnThe crouch. While crouching, _carry() moves her legs' rest height down along the clip's hips. That's the part of _carry() that stage 8 left out. Her legs are stiffer for it (JUMP_BOUNCE, 6 Hz), so they keep up with the clip.
The spring. At the bottom of the crouch she's thrown upwards:
func _spring(state: PhysicsDirectBodyState3D, xf: Transform3D) -> void:
crouching = false
airborne = true
_air_time = 0.0
var climb := maxf(_jump_rise - (xf.origin.y - _terrain), 0.1)
_jump_speed = sqrt(2.0 * 9.8 * jump_gravity * climb)
# (plus what this step's gravity takes off again)
var lost := 9.8 * jump_gravity * state.step
state.apply_central_impulse(Vector3.UP * mass * (_jump_speed + lost - state.linear_velocity.y))_jump_speed is the speed that carries something climb metres up against that gravity, and climb is how high the clip's hips rise.
The flight. _fly() draws her feet up and reaches them down again as the clip's do, and moves the clip's clock by how far through the flight she is. She can still steer a little (air_steer).
The landing. When a falling foot meets the ground, _land() plants both, and the clock runs on through the clip's squash.
Heavier gravity. The clip is quicker than real gravity allows. So through a jump she falls jump_gravity (2.5) times as hard, which brings the two close:
if jump_clock >= 0.0 and _heavy: # (a jump falls harder, to be as quick as its clip)
state.apply_central_force(Vector3.DOWN * mass * 9.8 * (jump_gravity - 1.0))Measured in the rebuilt project: she crouches 0.15 m, leaves the ground 0.23 s after the key, rises 0.44 m (the clip's hips rise 0.41), lands at 0.63 s and squashes 0.16 m.
Why it's like this
The first jump was a short crouch, a fixed upward speed under real gravity, and straight, dangling legs. The owner found it "very off".
Try it
On Leela in the Remote tree (the first two rows are in her Jump group; Filter Properties finds all three by name):
| Property | From | Try | What happens (measured) |
|---|---|---|---|
| Jump Gravity | 2.5 | 1 | Just as high, but floaty: she lands at 0.83 s, not 0.63. |
| Jump Gravity | 2.5 | 4 | Snappy: down by 0.53 s. |
| Bounce Damping | 0.9 | 0.1 | Stage 8's damper again: she bobs for about three seconds after landing. |
Turning, zooming and resetting the camera
iso_camera.gd has had these since stage 5:
func _unhandled_input(event: InputEvent) -> void:
var drag := event as InputEventMouseMotion
var wheel := event as InputEventMouseButton
var key := event as InputEventKey
if drag and drag.button_mask & MOUSE_BUTTON_MASK_MIDDLE:
_turning_home = false # (the drag takes over)
yaw = fposmod(yaw - drag.relative.x * turn_speed, 360.0)
elif wheel and wheel.pressed and wheel.button_index == MOUSE_BUTTON_WHEEL_UP:
view_height = maxf(view_height * (1.0 - zoom_step), minf(zoom_near, view_height))
elif wheel and wheel.pressed and wheel.button_index == MOUSE_BUTTON_WHEEL_DOWN:
view_height = minf(view_height * (1.0 + zoom_step), maxf(zoom_far, view_height))
elif key and key.pressed and not key.echo and key.keycode == KEY_R:
reset_view()- Drag with the middle mouse button to turn the camera: 0.3° for each pixel. The pitch stays at −30°, so tiles stay 2:1 from any side. And because
robot.gdsteers by the camera's yaw, W is still up the screen. - The wheel zooms by 12% a notch, between
zoom_near(2 m) andzoom_far(14 m). The view doesn't jump:_shown, the height really on screen, eases towardsview_height, and the pixel grid is worked out from_shown. - R takes both back to how the scene started them:
reset_view(). The turn eases home the short way round and finishes exactly on the starting yaw, so the tiles are 2:1 again to the pixel.
What's only named
These are in the repo and work. Each is a file or two to read once the main path makes sense. AGENTS.md's section "The robots" has the history of all of them.
| What | Where to read |
|---|---|
| George, the second robot (taller, with arms), and switching between robots with Tab. He's hidden in the repo's scene, which takes him out of play. | robots/george.tscn, robots/george.tres, and _ready() and _switch_to() in robots/robots.gd. He runs the same robot.gd and rig.gd as Leela. |
| Knocking parts off and sending them home. Works in your rebuild since stage 10. | robots/parts.gd (which part a click meets, cutting it out of the mesh, putting it back) and robots/piece.gd (the loose piece, and its flight home on a SecondOrder). The clicks are _knock() and _call_home() in robots.gd. |
| What she does with parts missing: her weight shifts, she hops on one leg, wanders with no head, and with no legs lies on what's left of her. | lose(), regain(), _lie_down(), _get_up() and _stand_when_clear() in robots/robot.gd, and whats_left() in parts.gd. |
| Chasing the mouse (F): she runs after the mouse's point on a second-order spring, overshoots and settles. | _chase() in robot.gd, and its numbers in Chase → Follow Spring. |
| The stand-in, the capsule that was here before the robots. A CharacterBody3D, moved the ordinary way: a useful contrast with stage 8. | probe/probe.gd. |
Checkpoint: the whole playground
Under Level you now have nine pieces: Ground and the eight in the table. Run it and go round them:
- Up the stairs, across the platform and off its edge.
- Space on the flat: a crouch, a jump, and a squash as she lands.
- Hold the middle mouse button and drag: the view turns, and W still goes up the screen. The wheel zooms. R takes both back.