Rebuilding Procedural Playground by hand
Stage 7 of 11: all the posts
  1. Before you start
  2. 1A new project
  3. 2Leela's model and texture
  4. 3The ground, the sun and the dusk
  5. 4Second-order dynamics
  6. 5The camera
  7. 6The picture
  8. 7Leela's scene
  9. 8Standing and walking on physics
  10. 9Her bones
  11. 10The player's keys
  12. 11Going further
  13. Last: full screen
  14. How this was checked

Stage 7 of 11

Leela's scene

By the end

  • robots/leela.tscn: a rigid body with a collider round her body, her model turned and scaled, her weight, her layers and her groups.
  • Leela in the playground, with the camera on her.

She has no script yet. When you run it she drops and stops with her legs sunk in the floor, and that's the right result.

Leela gets a scene of her own, so the main scene only has to place her. This stage builds it with no script at all, and what happens when you run it is worth seeing.

Her body

  1. Scene → New Scene. Under Create Root Node: press Other Node and choose RigidBody3D. Name it Leela and save the scene (Ctrl+S) as res://robots/leela.tscn. The dialog already offers leela.tscn, from the root's name: open robots in it, then Save.

    A RigidBody3D is a body the physics engine moves: it has weight, it falls, and only forces move it. That's the point of the whole project, and stage 8 comes back to it.

  2. Add a CollisionShape3D under it and name it Shape. (The name matters: stage 8's script asks for $Shape.) Set:
SectionPropertyValueWhy
ShapeNew → CylinderShape3D, then inside it:
→ Height0.67
→ Radius0.4Her knees and toes reach 0.37 to 0.40 m from her middle. At 0.3 they went into walls.
TransformPosition0, 0.665, 0The cylinder then runs from 0.33 m up to 1.0 m.

Her collider is only her body. It stops 0.33 m above her feet. Her legs have no collider at all: they'll hold her up by pushing, and the room under her is what lets her crouch, land and step over things.

  1. Select Leela and press the chain-link button at the top of the Scene dock. (Instantiate Child Scene... on a node's right-click menu is the same thing.) Select Scene lists the project's scenes: one click on Leela.blend picks it. The new node arrives named Leela2. Rename it Model. (This name matters too: $Model.) Set:
SectionPropertyValueWhy
TransformRotation0, 180, 0She faces +Z in her file. Forwards is −Z here.
Scale0.2, 0.2, 0.25.3 units tall becomes 1.05 m. Type it into x: the chain at the row's end keeps the three the same.

Her feet are now at the scene's origin, and her collider is round her body.

Clip · 1:27 · no sound The three steps: the new scene and its root, the save, the collider and its cylinder, then her model brought in, renamed, turned and scaled.

Her weight

Select Leela and set:

SectionPropertyValueWhy
Mass30 kg
Physics Material OverrideNew → PhysicsMaterial, with Friction 0.2So her collider slides along walls and off edges and doesn't grip them. The grip that moves her isn't friction: it's a number in stage 8's script.
Mass DistributionCenter of Mass ModeCustomSo you say where her weight is. Left on Auto, it's the middle of the collider, and stage 8's script reshapes the collider.
Center of Mass0, 0.62, 0A little above her hips. The row shows once the mode is Custom.
Inertia1.5, 1, 1.5How hard she is to turn about each axis. Fixed for the same reason.
DeactivationCan SleepOffA body at rest "falls asleep" and the engine stops running it. Her legs are forces applied every tick: asleep, she'd never take another step.
CollisionLayer2 only (click box 1 off and box 2 on)Layer 2 is "robots".
Mask1 and 4 (box 4 on as well)What she bumps into: the level (1) and loose parts (4).
Clip · 1:00 · no sound The whole table, top to bottom. The PhysicsMaterial is made in its slot, opened with a click to set Friction, and shut with another. Each row of layer boxes is two blocks of eight, numbered along the rows.

Layers in this project. A body's layer says what it is, and its mask says what it bumps into.

LayerWhat's on it
1The level. The only layer her feet's rays look for.
2Robots.
4Parts knocked off a robot.
13The stairs' hidden smooth slope, for bodies that glide. Not for her.

Her groups

With Leela selected, open the Groups dock and put her in two groups, making each with + as in stage 6:

  • outline, as the repo's Leela is. (You made a group of that name in main.tscn. Groups made this way belong to their scene, so make it again here. The same name is the same group.)
  • psx_character, which hands her materials to Psx (stage 6).

Save the scene.

Put her in the playground

  1. In main.tscn, add a Node3D under Main and name it Robots.
  2. Drag leela.tscn from the FileSystem dock onto Robots. Set the new Leela's Position to 1.4, 0.05, 4.6. (The repo's spot: 5 cm up, so she drops onto the floor.)
  3. Select Camera and set its Target to Leela with Assign....
  4. Delete StandIn.

Checkpoint

Run it. Leela is a white statue, standing stiff, and she drops at once and stops with her legs sunk in the floor to above the knees. (Measured: she comes to rest 0.33 m down in half a second, upright.)

That's exactly right, and it's the picture to keep in mind for stage 8:

  • She's white because her material isn't on her yet. Stage 9's script puts it on.
  • She's stiff because nothing moves her bones.
  • She's sunk because her collider is only her body. Her legs are just a picture so far. The floor stops the cylinder, 0.33 m up from her feet.

If not:

  • She falls through the floor and away: her Mask hasn't got layer 1, or Ground isn't a Block.
  • She's a giant: Model's Scale.
  • She isn't there at all: the model didn't import (stage 2).