Skip to content

Tutorials · Physics and Mechanisms · Chapter 12

The flooded cellar

30 minutes Uses: Effector, CharacterBody, Confiner, Sprite

By the end

  • A cellar painted under the ground floor with the tilemap’s Pick, Stamp and Erase: its walls, its base, a pier, and H0 cut through the ground floor’s slab
  • A hatch over H0, a One Way plank he walks over and drops through with S and Space
  • Water: an Effector of the Buoyancy kind, its Waterline the water’s top, its Density the lift that floats him and a crate two-thirds under, its Drag what stops his plunge
  • His Swim Stroke, the one way up out of water: through H0 onto the hatch, or onto the pier, where the water is shallow enough to wade
  • A crate shoved off the pier that glides, slows and floats at the line its density sets
On this page

Under the ground floor

Under the ground floor is a cellar, flooded. It is off the climb, so there is no floor to skip to: its hatch is a few steps east of the knight’s start, and every run on this page starts there. The tower grows down to make room for it. Since y grows downward, nothing above moves, and his start stays 48, 1792.

  1. Select tower, click + Add node and choose Node. Rename it cellar. The hatch, the water and the crate in this chapter go under it; the cellar’s backdrop goes under backdrop, with the others.
  2. Keep Collision, Triggers, Forces and Bodies ticked in the Gizmos menu under the Viewport, as chapter 9 left them. The pictures on this page have all four on.

The cellar, painted

The tower’s tilemap ends at row 113, the ground floor’s slab. The cellar is rows 114 to 127 under it: a room 192 tall, from y 1824, the slab’s underside, to y 2016, its base’s top. Its walls, its base and a pier standing on its floor are all copies of cells the tower already has, lifted with Pick and put down with Stamp, as chapter 10 laid the loft’s floor. Then Erase cuts H0, a hole through the ground floor’s slab, a few steps east of his start. Copy the floor before you cut the hole, or the copies carry it.

  1. Select stone in the Hierarchy and open the Tilemap tab beside the Inspector. Under Layers, click stone.
  2. Click Pick, or press I over the Viewport, and drag over the west wall’s two cells just over the ground floor: column 0 of rows 110 and 111, x 0, y 1760 to 1792.
  3. Click Stamp, or press S, and click column 0 of row 114, x 0, y 1824. Click again at rows 116, 118, 120, 122, 124 and 126, y 1856, 1888, 1920, 1952, 1984 and 2016: the west wall, down to y 2048.
  4. With Pick, drag over the east wall’s two cells the same way: column 39 of rows 110 and 111, x 624.
  5. With Stamp, click column 39 of row 114, x 624, y 1824, and again at rows 116, 118, 120, 122, 124 and 126.
  6. With Pick, drag over the ground floor’s floor, both its rows, 112 and 113, from column 1 to column 38: x 16 to 624, y 1792 to 1824.
  7. With Stamp, click column 1 of row 126, x 16, y 2016: the cellar’s base, its top 224 under the ground floor’s.
  8. With Pick, drag over columns 18 to 25 of the same floor, both rows: x 288 to 416.
  9. With Stamp, click column 18 of row 117, x 288, y 1872: the pier’s moss-capped top.
  10. With Pick, drag over the storeroom’s inner wall, the one over the doorway its portcullis shuts: columns 16 and 17 of rows 87 to 93, x 256 to 288, y 1392 to 1504.
  11. With Stamp, click row 119, y 1904, at columns 18, 20, 22 and 24, x 288, 320, 352 and 384: the pier’s stone, from under its top down to the cellar’s floor.
  12. Click Erase, or press E, and drag over columns 6 to 9 of rows 112 and 113: x 96 to 160, y 1792 to 1824. That is H0.
  13. Click Save at the top of the Tilemap panel.
The editor with the cellar framed at 135%: across the top the ground floor, the knight at its west end, a short gap in its floor a few steps east of him with two small planks over it, the round stump and the steps beyond; under the floor’s slab a dark room flooded almost to its top, a stone pier under the water in its middle and a crate on it, a stone floor at the bottom; thin green boxes drawn round the slab with a gap at the hole, round the pier and down the walls; the Tilemap tab on the right with Paint mode on, Pick chosen among the tools and its line Click reads a cell into the brush; drag lifts a block out, the layer stone chosen, and the Tileset fold; the bar at the bottom reads Collision: 19 rects from 994 tiles
The cellar painted, with Pick chosen and stone the layer: the green boxes are the tilemap’s collision, drawn while the Tilemap tab is open. H0 is the gap in the slab’s box.
Erase
The tilemap painter’s Erase, E: clears every cell the drag passes over, on the chosen layer. A cleared cell of a solid layer stops nothing, so H0 is a hole through the slab’s stone.

The pier stands on the cellar’s floor from x 288 to 416, its top at y 1872. Save writes the tilemap, its own file in art; Ctrl+S saves it with the scene.

The camera and the backdrop

The camera follows him, but the Confiner keeps its view inside the tower as it was, down to the ground floor. Grown over the cellar, it lets the view follow him down. Behind the cellar goes the castle’s hall, as behind every floor.

  1. Select confiner and set its Position to 320, 1024 and its Bounds to 640, 2048: the whole tower as it now is, from y 0 to 2048.
  2. Select backdrop, click + Add node and choose Sprite. Rename it backdrop_cellar and set its Position to 0, 1792. Drag art/old-dark-castle-interior-background.png onto Texture, set Size to 640, 224, Anchor to 0, 0 and Sort Layer to -10, and in its Draw mode fold set Draw Mode to Tiled and Tile Size to 960, 304, as the eight backdrops above it.
The Confiner’s Bounds
The Confiner’s Bounds: the rectangle the camera’s view is kept inside, its width and height in world units, centred on the Confiner’s Position. 640 by 2048 at 320, 1024 runs from the tower’s top to the cellar’s bottom.

A hatch over H0

A hole a few steps from his start would drop him the moment he walked east. A hatch over it is a plank he walks over, as over the floor, and drops through when he means to: chapter 3’s One Way scaffolding, laid flush with the floor. Two leaves, one picture flipped, meet over H0’s middle, x 128.

  1. Select cellar, click + Add node and choose Sprite. Rename it hatch and set its Position to 128, 1796. Drag art/hatch.png onto Texture, and set Size to 32, 8, Anchor to 1, 0.5 and Sort Layer to 1: the west leaf, from x 96 to 128.
  2. Click Add component and choose ColliderComponent. Set its Size to 64, 8 and tick One Way: one plank over the whole of H0, its top at y 1792, flush with the floor.
  3. Select hatch, click + Add node and choose Sprite. Rename it hatch_east; its Position stays 0, 0. Drag art/hatch.png onto Texture, set Size to 32, 8, Anchor to 0, 0.5 and Sort Layer to 1, and tick Flip › X: the east leaf, from x 128 to 160, hinged at H0’s east face.

Standing on it, S with Space drops him through, as through chapter 3’s planks; with one foot on the stone beside it, the same keys jump. So stand him wholly on the hatch first: from his start, about half a second of D.

The water

The water is an Effector, as chapter 10’s updraft is, of another kind: Buoyancy. Its Area is where it acts, the whole cellar room; its Waterline is where its top is. A body in the Area is lifted by how much of it is under the line, and its fall is slowed by the same share.

  1. Select cellar, click + Add node and choose Effector. Rename it water and set its Position to 320, 1858.
  2. In its Area, open Shape and set Size to 608, 192 and Offset to 0, 62: the cellar room, x 16 to 624, y 1824 to 2016. Click the button beside Mask, untick World, and tick Knight and Crate, as every effector’s in the tower.
  3. In its Effector, set Kind to Buoyancy, Waterline to 2, Density to 1.5 and Drag to 5. Leave Priority at 0 and Enabled ticked.
  4. Click Add component and choose SpriteComponent. Drag art/water-surface.png onto Texture, set Size to 608, 8, Anchor to 0.5, 0 and Sort Layer to 6, and in Draw mode choose Tiled with a Tile Size of 16, 8: the foam along the water’s top.
  5. Select water, click + Add node and choose Sprite. Rename it water_depth and set its Position to 0, 8. Drag art/water.png onto Texture, set Size to 608, 150, Anchor to 0.5, 0 and Sort Layer to 6, and choose Tiled with a Tile Size of 16, 16: the water, down to the floor.
The editor with water selected and framed at 135%: the ground floor across the top, the knight at its west end and the hatch’s two planks over the gap east of him; under the slab the cellar, a yellow box with handles round the whole room, the water filling it from a line of foam near the top to the floor, a thin orange line along the foam, a dashed line down the middle from a small circle on the foam, the pier faint under the water and the crate on it outlined in rose; the Inspector narrowed to effector: the EffectorComponent, Kind Buoyancy with a dot, Acceleration 0.0 and -600.0, Max Speed 0, Strength 800.00, Falloff Linear, Radius 128.00, Surface Speed 120.00 and Grip 10.00 dim, Waterline 2.00, Density 1.50 and Drag 5.00 bright with dots, Priority 0, Enabled ticked
The water: its Area the cellar room, its Waterline 2 under the node, drawn by the Forces gizmo along the foam.
Kind › Buoyancy
The Effector’s Kind for water. Every step it lifts each body in its Area by its Density times the body’s own Gravity times the share of the body under its Waterline, and slows the body’s fall or rise by its Drag times the same share. A body in the Area wholly over the line is neither lifted nor slowed. It reads Waterline, Density and Drag, and dims the rows of the other kinds. Unity’s Buoyancy Effector 2D is the same idea, its Surface Level this Waterline; Godot has no water of its own.
Waterline
The Effector’s Waterline: where the water’s top is, in world units under the node’s own Position, not the Area’s. The node is at y 1858, so 2 puts the top at y 1860, 36 under the cellar’s ceiling. The Forces gizmo draws it as a line across the Area. The pictures do not follow it: they hang from the node. A new Effector’s is 0.
Density
The Effector’s Density: the lift on a body wholly under, as a multiple of that body’s own Gravity; a body partly under gets that share of it. A body floats still where the lift is its weight, with one part in Density of it under: at 1.5, two-thirds. A crate, 24 tall, floats with 16 under; the knight, 30 tall, with 20. Since it counts against each body’s own Gravity, his 2000 and a crate’s 1800 float alike. A new Effector’s is 1.2.
Drag
The Effector’s Drag: how much of a body’s motion the water takes away each second, times the share of it under; at 5, a body all under loses a twelfth of it each step. It takes the share of the motion the world gave: the body’s fall and rise, and its Drift, such as a shove’s glide. It never takes what the body’s own keys or script drive, so in the water he walks, and floats along, at his full Speed. Drag is what stops his plunge short of the floor and stills his bob. A new Effector’s is 4.

A crate on the pier

  1. Right-click crate_5 in the Hierarchy and choose Duplicate. Drag the copy onto cellar, rename it crate_11, and set its Position to 392, 1872: on the pier’s east end.

Over the pier the water is 12 deep. A crate needs 16 under to float and the knight 20, more than the water there is, so neither floats on the pier: the crate rests on it, and he stands. The pier is the cellar’s shallows.

Down the hatch

  1. Select water, so its waterline is drawn bright, and press F5.
  2. Hold D for about half a second, until he stands on the hatch, and let go. He stands on it as on the floor.
  3. Press S and Space together. He drops through the hatch, through H0, and the camera follows him down into the water.
  4. Move the pointer over the Viewport and press F: the Viewport frames water, the whole cellar, as in the pictures. Watch him plunge, bob back up past where he comes to rest, and settle. The plunge is over in a second: to see it step by step, press Pause or F6 as he drops, then Step or F7, and watch the Play bar’s step counter. Press F5 to stop.
Six tall frames of the column under the hatch, the ground floor’s slab across the top with the two hatch planks in it and the water filling the lower half: in the first the knight stands on the planks, a rose arrow pointing east from his box; in the second he is halfway through them, a rose arrow pointing down; in the third he is under the slab, falling, the arrow down long; in the fourth his feet are in the foam; in the fifth he is under the water, tinted blue, still going down; in the sixth he is lower still, his arrow short; a thin yellow line along the slab’s underside and a thin orange line along the foam
Steps 31, 37, 43, 48, 55 and 64 (0.52, 0.62, 0.72, 0.80, 0.92 and 1.07 s), the editor in Play at 135%, water selected and framed: D held from step 0 to 31 walks him from his start onto the hatch, and S with Space from 32 to 33 drops him through it. He falls 68 to the water’s top, and the water stops him on step 64, his feet 54 under where he will float and 82 over the cellar’s floor.
Five frames of the same column, lower, the foam line across each: in the first the knight is deep under the water; in the second he has bobbed up, his feet near the foam and his head and cape over it; in the third he is lower again, a little arrow pointing down; in the fourth up again; in the fifth he floats still, his feet under the foam and his chest and head over it
The same run: steps 64, 100, 120, 140 and 400 (1.07, 1.67, 2.00, 2.33 and 6.67 s). On step 100 his feet are 13 over his line, on step 120 7 under it, each bob smaller; by step 400 he floats still, his feet 20 under the water’s top.

Afloat, his Grounded is never ticked: he stands on nothing. So his jump is no jump, and his State Machine, which picks his clips from what his body says, plays his fall clip the whole time he floats, bobbing up or down.

A stroke

Floating, he cannot jump, and nothing else lifts him: the hatch is over his head, out of reach of the water’s lift. A Swim Stroke is his way out. It is a field of his Character Body, in the Jumping fold beside Air Jumps, which chapter 3 left at 0.

  1. Press F5 to stop if the game is running. Select knight, and in his Character Body’s Jumping fold set Swim Stroke to 680, the same as his Jump Speed.
The Inspector’s column for knight, narrowed to character: his CharacterBodyComponent, Size 12.0 and 30.0, Gravity 2000.00, Terminal Velocity 1000.00, Speed 160.00, Jump Speed 680.00; the Jumping fold, Coyote Time 0.10, Jump Buffer 0.10, Jump Cut 0.50, Air Jumps 0, Swim Stroke 680 with a dot, Rope Jump 0; the Slopes fold, Step Height 12, Floor Snap Length 12, Floor Max Angle 0.7854, Max Slides 4
His Swim Stroke, 680, in the Jumping fold.
Swim Stroke
The Character Body’s Swim Stroke, in its Jumping fold, in world units a second: the upward speed a press of jump sets while the middle of his box is under a Buoyancy waterline and he is neither on the ground nor within his Coyote Time. Once a press: held, it strokes once; let go and pressed again, it strokes again. Letting go does not cut it short, as it cuts a jump, and it spends no air jump. On the ground a press is a jump, as ever. With his middle out of the water, at the top of a stroke’s rise, a press is nothing. His 680, his Jump Speed, lifts him from his line out through H0. 0, as it comes, cannot swim.
  1. Select water and press F5. Walk him onto the hatch with D, drop through with S and Space, and press F over the Viewport.
  2. Wait until he floats still under the hatch, about six seconds after the drop. Press Space once. He rises out of the water, up through H0 and past the hatch, which lets him through from below, and lands on it, where he went down. Press F5 to stop.
Six tall frames of the column under the hatch: in the first the knight floats at the foam line, his head and chest over it; in the second he is out of the water, rising, a long rose arrow up from his box; in the third he is in the gap in the slab; in the fourth his feet are level with the hatch planks; in the fifth he is over them, the arrow gone; in the sixth he stands on the planks
The drop’s keys, and Space from step 400 to 401: steps 400, 404, 408, 413, 420 and 430 (6.67, 6.73, 6.80, 6.88, 7.00 and 7.17 s). His feet top out on step 420, 20 over the hatch’s top, and he lands on it on step 430.

Taken while he still plunges or bobs, a stroke works too, as long as his middle is under. Two strokes from the bottom of his plunge, the second pressed after the first is let go of, bring his middle up over the water’s top in under half the time the water alone takes.

Four frames of the column under the hatch, lower, the foam line across each: in the first the knight is deep under the water at the bottom of his plunge, tinted blue, a little rose arrow pointing down; in the second he is rising, his head at the foam, a long rose arrow up; in the third his head and cape are over the water; in the fourth he is half out of it, the middle of his box over the foam, the arrow still up
The drop’s keys, then Space from step 64 to 68, held from the bottom of his plunge, and again from 69 to 70: steps 64, 67, 69 and 71 (1.07, 1.12, 1.15 and 1.18 s). The strokes go down on steps 65 and 70, and his middle is over the water’s top on step 71. With no stroke the water alone takes him there on step 94: the bob strip above has him still deep on step 64 and bobbed up by step 100.

Try it: no stroke

  1. Select knight and set Swim Stroke to 0, what he had before this chapter.
  2. Select water, press F5, walk onto the hatch and drop through. Press Space as often as you like, in his plunge and once he floats: nothing lifts him, and he floats under the hatch for good. Press F5 to stop.
  3. Set Swim Stroke back to 680.
Three tall frames of the column under the hatch, each the same: the knight floating at the foam line, his head and chest over it, the hatch planks far over him
For comparison, with Swim Stroke typed 0, and Space from step 400 to 401 as above: steps 400, 410 and 420 (6.67, 6.83 and 7.00 s). He stays at his line.

The pier and the crate

  1. Select water and press F5. Walk onto the hatch, drop through, press F over the Viewport, and wait until he floats still.
  2. Hold D. He floats east at his walk until the pier’s face stops him, its top 8 over his feet.
  3. Keep D held and press Space: a stroke lifts him over the pier’s top, and he lands on it, the water to his knees.
  4. Keep D held. He wades east at his full walk, meets the crate and shoves it off the pier’s east end. Let go of D once the crate is off, before he follows it. The crate glides on through the deep water, slows, bobs and floats still. Press F5 to stop.
Five frames of the water west of the pier, the ground floor’s slab across the top: in the first the knight floats east at the foam line, a rose arrow east from his box; in the second he floats against the pier’s face, the pier’s top faint under the water at his feet; in the third he is up over the water above the pier, a rose arrow pointing right and down; in the fourth he stands on the pier, the water to his knees; in the fifth he stands further east on it
The drop’s keys, then D from step 400 to 514 and Space from 460 to 461: steps 445, 458, 465, 475 and 490 (7.42, 7.63, 7.75, 7.92 and 8.17 s). The pier’s face stops him on step 458; he lands on its top on step 475 and wades on at his walk, 2.67 a step, as on dry stone.
Five frames of the pier’s east end and the water beyond it: in the first the knight stands against the crate on the pier, the crate’s rose box drawn; in the second the crate is past the pier’s end, an orange arrow pointing east under it; in the third the crate sits in the water east of the pier, a shorter orange arrow under it, the knight standing at the pier’s end; in the fourth it is a little further east, no arrow; in the fifth it floats in the same place, two-thirds under, its top over the foam
The same run as the strip above: steps 494, 514, 530, 560 and 800 (8.23, 8.57, 8.83, 9.33 and 13.33 s). He meets the crate on step 494; D is let go of on step 514, with the crate off the pier’s end. Its glide, the orange Drift arrow, is bled by the Drag times its share under, and it comes to rest at x 463.5, floating at y 1876, its bottom 16 under the water’s top.
Step Height, afloat
The Character Body’s Step Height, in its Slopes fold, which chapter 3 set to 12: the highest step he walks up as he walks, from the ground (or on the step he lands). Afloat he is neither, so it climbs nothing, however small the step.

Try the water’s fields

Try it: no drag

  1. Select water and set Drag to 0.
  2. Press F5, walk onto the hatch, drop through and press F over the Viewport. Nothing slows his plunge: he goes down to the cellar’s floor, the water throws him back up out of it into H0, and down he goes again, deep into the water. Press F5 to stop.
  3. Set Drag back to 5.
Six tall frames of the column under the hatch, from the slab down to the cellar’s floor: in the first the knight plunges into the water, a long rose arrow down; in the second he is deep in it; in the third he stands on the cellar’s floor; in the fourth he is rising through the water, a long arrow up; in the fifth he is out of the water, up in the gap in the slab; in the sixth he is deep in the water again, falling
For comparison, with Drag typed 0: steps 50, 60, 70, 100, 120 and 150 (0.83, 1.00, 1.17, 1.67, 2.00 and 2.50 s), the keys as in the drop strip. He reaches the floor on step 70, is thrown up out of the water by step 120, and by step 150 is deep in it again, falling.

Try it: a lower waterline

  1. Select water and set Waterline to 40. The gizmo’s line drops 38; the foam does not move, since the pictures hang from the node.
  2. Press F5, walk onto the hatch, drop through and press F over the Viewport. He floats 38 lower, at the new line. Once he floats still, press Space: the stroke lifts him into H0, but from there his feet stay short of the hatch’s top, and he falls back into the water. Press F5 to stop.
  3. Set Waterline back to 2.
Six tall frames of the column under the hatch, a thin orange line across the water well under the foam: in the first the knight floats with his middle at the orange line, under the foam; in the second he rises out of the water, a long rose arrow up; in the third he is under the slab, still rising; in the fourth he is in the gap in the slab, his feet under the hatch planks; in the fifth he is falling back, a rose arrow down; in the sixth he is deep in the water
For comparison, with Waterline typed 40, and Space from step 400 to 401: steps 400, 405, 410, 420, 430 and 450 (6.67, 6.75, 6.83, 7.00, 7.17 and 7.50 s). His feet top out on step 420, 18 under the hatch’s top.

Try it: denser water

  1. Select water and set Density to 2.5.
  2. Press F5, walk onto the hatch, drop through and press F over the Viewport. He floats higher, with two-fifths of him under, his middle over the water. Press Space: nothing, for a stroke asks for his middle under. Press F5 to stop.
  3. Set Density back to 1.5.
Two frames of the column under the hatch, the same: the knight floating high, his feet a little under the foam, most of him over the water
For comparison, with Density typed 2.5, and Space from step 400 to 401: steps 400 and 420 (6.67 and 7.00 s). His feet are 12 under the water’s top, and the press changed nothing.

The way back up

Without a stroke he would never leave the cellar: nowhere else in it leads out, and afloat he climbs onto nothing. With one, the way back up is the way he came: from rest under H0, Space lifts him through it, clear of its sides, and up past the hatch, his feet 15 or more over its top, and he lands on it where he went down.

The cellar is off the climb. The whole climb still goes from his start up to the belfry’s floor, walking over the hatch on the way, and every jump on it clears what it reaches by 15 or more.

The cellar

WhereWhatCellsValue
stone, layer stonewest wallcolumn 0, rows 114 to 127the wall’s two cells over the ground floor, stamped at rows 114, 116 … 126
east wallcolumn 39, rows 114 to 127the same, column 39
basecolumns 1 to 38, rows 126, 127the ground floor’s floor, stamped at column 1 of row 126
pier’s topcolumns 18 to 25, rows 117, 118the ground floor’s floor, stamped at column 18 of row 117
pier’s stonecolumns 18 to 25, rows 119 to 125the storeroom’s inner wall, stamped at columns 18, 20, 22, 24 of row 119
H0columns 6 to 9, rows 112, 113erased
NodeComponentFieldValue
confinerPosition320, 1024
ConfinerBounds640, 2048
backdrop_cellarPosition0, 1792, under backdrop
SpriteTexture, Sizeold-dark-castle-interior-background.png, 640, 224
Anchor, Sort Layer0, 0; -10
Draw Mode, Tile SizeTiled, 960, 304
cellar(a Node)under tower
hatchPosition128, 1796
SpriteTexture, Sizehatch.png, 32, 8
Anchor, Sort Layer1, 0.5; 1
ColliderSize, One Way64, 8; ticked
hatch_eastPosition0, 0, under hatch
SpriteTexture, Sizehatch.png, 32, 8
Anchor, Sort Layer0, 0.5; 1
Flip › Xticked
NodeComponentFieldValue
waterPosition320, 1858
AreaShape › Size, Offset608, 192; 0, 62
MaskKnight, Crate
EffectorKindBuoyancy
Waterline, Density, Drag2; 1.5; 5
SpriteTexture, Sizewater-surface.png, 608, 8
Anchor, Sort Layer0.5, 0; 6
Draw Mode, Tile SizeTiled, 16, 8
water_depthPosition0, 8, under water
SpriteTexture, Sizewater.png, 608, 150
Anchor, Sort Layer0.5, 0; 6
Draw Mode, Tile SizeTiled, 16, 16
crate_11Position392, 1872, a copy of crate_5
knightCharacter BodySwim Stroke680

Every new node but backdrop_cellar is under cellar, and every other field is as it comes.

Check it works