Skip to content

Tutorials · Physics and Mechanisms · Chapter 7

The pendulum

25 minutes Uses: Joint, RemoteTransform, CharacterBody, Collider, Sprite

By the end

  • A clock face and its hand, a bodiless pivot at the hub, and a bob with a Character Body and a round Collider
  • A Joint: Kind Distance, Target pivot, its Anchor the bob’s rim, Length the rod’s, Turns Body on: a rod that swings for good
  • A Remote Transform that turns the clock’s hand as the bob turns, and leaves it on its hub
  • The knight riding the bob across the gap, and jumping from its far turn up to the gallery
  • The gallery’s two ledges, and the break between them that no jump crosses
On this page

Start on this floor

The clockworks are the floor over the ice hall. Chapter 6’s climb leaves the knight on their floor, off the top scaffold plank; to start there, set his Position before Play, as in chapter 6.

  1. Select knight and set his Position to 488, 1120. Press F5: he stands on the clockworks’ floor, by the opening he came up through, and west of him the floor stops at a gap. Press F5 to stop.
  2. Set his Position back to 48, 1792, or press Ctrl+Z.

That gap, gap A, runs from x 320 to 448, too wide to jump. Over it hangs the room’s clock, and from the clock’s hub the pendulum this chapter builds, which carries him across.

The clock face and its hand

  1. Select tower in the Hierarchy, click + Add node and choose Node. Rename it clockworks. Its Position stays 0, 0.
  2. Select clockworks, click + Add node and choose Sprite. Rename it clock_face and set its Position to 384, 996: the hub, over the gap’s middle. In its Sprite, drag art/clock-face.png from Assets onto Texture, set its Size to 128, 128 and its Sort Layer to -2, in front of the room’s backdrop. Leave its Anchor at 0.5, 0.5, so the node is at the face’s middle.
  3. Select clock_face, click + Add node and choose Sprite. Rename it clock_hand. Its Position stays 0, 0: the face’s middle. Set its Rotation to -53.13.
  4. In its Sprite, drag art/clock-hand.png onto Texture, and set its Size to 8, 64, its Anchor to 0.5, 0.75, so it turns about its own hub, a quarter of the way up from its foot, and its Sort Layer to -1.

The hand is turned now as the bob will be, so that before Play the hand and the pendulum’s rod make one line through the hub. In Play the bob turns it.

The pivot and the bob

The pendulum is two nodes: pivot, a bare Node at the hub that the joint hangs from, and bob, the round weight that swings, with its rod as a child Sprite. The bob is pulled out to the east end of its swing and turned to match, its rod pointing at the hub.

  1. Select clockworks, click + Add node and choose Node. Rename it pivot and set its Position to 384, 996, the hub. Give it nothing else.
  2. Select clockworks, click + Add node and choose Sprite. Rename it bob, set its Position to 448, 1044 and its Rotation to -53.13. In its Sprite, drag art/pendulum-bob.png onto Texture, set its Size to 32, 32 and its Sort Layer to 2. Leave its Anchor at 0.5, 0.5: the node is the bob’s middle.
  3. Select bob, click + Add node and choose Sprite. Rename it rod and set its Position to 0, -16: the bob’s rim. In its Sprite, drag art/pendulum-rod.png onto Texture, set its Size to 6, 64, its Anchor to 0.5, 1, hung from its foot, and its Sort Layer to 1.
  4. Select bob. Click Add component and choose CharacterBodyComponent. Set its Size to 32, 16 and its Driven By to Script. It gets no script: leave the rest as it comes.
  5. Click Add component and choose ColliderComponent. In its Kind, choose Circle. Set its Size to 32, 32 and, in its Polygon fold, its Step to 4. Solid stays ticked.

The bob is 64 east of the hub and 48 down, 53.13° out from straight down. Its Collider is a round as big as its picture, cut into steps of 4 as chapter 1’s stump is: that is what the knight stands on. The Character Body is what a joint can move; with Driven By Script and no script, nothing else moves it, and his keys never walk it.

The joint

A Joint on the bob holds it to the pivot. Its Kind says what it holds: a Distance joint keeps its two ends exactly a Length apart, a rod.

  1. With bob selected, click Add component and choose JointComponent. Until it names its other end, the Problems tab lists it: “this joint joins nothing — it needs the name of the node at its other end”.
  2. In its Kind, choose Distance. Type pivot into Target: the Problems row goes.
  3. Set its Anchor to 0, -16, the bob’s rim, where the rod meets it. Leave Target Anchor at 0, 0 and Length at 64, as they come: the pivot’s own point, and the rod’s length.
  4. Tick Turns Body. Leave Enabled ticked and, in the Limits fold, Use Limits unticked.
  5. In the Viewport’s Gizmos menu, tick Forces, and keep Collision, Bodies and Triggers ticked, as chapter 6 left them. The four stay ticked from here on. Forces draws joints in orange, at full strength on the selected node and at half strength on the rest.
The editor with bob selected and framed at 200%: the clock face over the gap in the clockworks’ floor, the bob pulled out to the lower right of the face, turned so its rod runs up and to the left to the hub, and the clock’s hand carrying the same line on up past the hub; a thin orange line along the rod from the bob’s rim to the hub, an orange cross at each end and the word Distance at the rim; at the upper left, under the ceiling, the gallery’s east ledge, which this chapter lays further down the page (the picture is of the chapter’s finished checkpoint); the Inspector narrowed to jointcomponent, the JointComponent alone: Kind Distance, Target pivot, Anchor 0.0 and -16.0, Target Anchor 0.0 and 0.0, Target Point and Axis dim, Length 64.00, Weld Angle dim, Turns Body ticked, Stiffness and Damping dim, Enabled ticked, Limits fold with Use Limits unticked, Motor fold with Use Motor, Speed and Max Step dim, Breaking fold with Break Stretch 0.00 u and Break Twist dim
The bob’s Joint, and its gizmo: the orange link from its Anchor, the rim, to its Target, the hub. The rod and the hand make one line through the hub. The Inspector’s search box, jointcomponent, keeps the Joint’s rows alone.

The rows a Distance joint does not read are dimmed, and hovering one says which kinds use it: Target Point, Axis, Weld Angle, Stiffness, Damping, the Motor fold’s three and Break Twist. Chapters 8 and 9 set all but Weld Angle on other kinds of joint; chapter 8’s lantern keeps its Weld Angle at 0, and chapter 14’s crooked sign is the first to set one. Break Stretch stays bright, as every kind reads it; chapter 8 sets one. Min and Max show only once Use Limits is ticked.

The Joint’s Kind
The Joint’s Kind: what it holds its node to. It comes as Pin. Distance keeps its two ends exactly its Length apart, as a rod would; the bob’s is a Distance joint. Chapter 8 uses Pin, Fixed and Groove, chapter 9 Slider, Spring and Target.
The Joint’s Target
The Joint’s Target: the node at its other end, by name. A node with no Character Body is an anchor: the joint never moves it, and moves only its own node. The bob’s is pivot, a bare Node at the hub. Empty, or a name nothing answers to, the joint holds nothing, and the Problems tab says so.
The Joint’s Anchor
The Joint’s Anchor: where on its own node the joint holds, in the node’s units from its Position. The bob’s is 0, -16, its rim, where the rod meets it: the joint holds the rim, not the bob’s middle, so the middle swings 80 from the hub, the Length and the rim’s 16. With Turns Body on, the Anchor turns with the node.
The Joint’s Target Anchor
The Joint’s Target Anchor: where on the target the joint holds, in the target’s units. 0, 0, as it comes, is the pivot’s own point, the hub. Chapter 8’s chain ties each link to a point on the one before.
The Joint’s Length
The Joint’s Length: how far apart a Distance joint holds its Anchor and its Target Anchor, in world units. It comes as 64, the rod picture’s length, so the bob’s needs nothing typed. With Use Limits ticked a Distance joint holds its ends between Min and Max instead, and the Length row dims.
The Joint’s Turns Body
The Joint’s Turns Body, for a Pin or a Distance joint: on, the node turns as it swings, its own down pointing along the joint away from the target, and its Anchor turns with it. The bob turns as far as it has swung, so its rim, and the rod its child, keep facing the hub. Off, as it comes, the node keeps the turn it was saved with. The bob’s is on.
The Joint’s Enabled
The Joint’s Enabled: whether the joint holds right now. It comes ticked, and the bob’s stays so. Unticked, it holds nothing and its gizmo is drawn dashed; chapter 8’s lever unticks one in Play.
The Joint’s Use Limits
The Joint’s Use Limits, in its Limits fold: ticked, the joint holds its ends within a range, its Min and Max, which show then; a Distance joint becomes a slack tie, free inside the range and taut at its ends. Unticked, as it comes and as the bob keeps it, a Distance joint is a rod. Chapter 8’s chain bridge ticks it.

The clock’s hand

The hand is the clock face’s child, and nothing moves it yet. A Remote Transform on the bob copies the bob’s turn onto it once a step: the hand turns as the rod does, and stays on its hub.

  1. With bob selected, click Add component and choose RemoteTransformComponent. Until it names a node, the Problems tab lists it: “this Remote Transform copies onto nothing — its Target is empty; type the name of the node that should follow this one”.
  2. Type clock_hand into Target.
  3. Tick Rotation, which comes unticked, and untick Position, which comes ticked. Leave Scale unticked, Offset at 0, 0 and Enabled ticked.
  4. Press Ctrl+S.
The Inspector’s column for bob, narrowed to remote: the RemoteTransformComponent with Target clock_hand, Position unticked, Rotation ticked, Scale unticked, Offset 0.0 and 0.0, Enabled ticked, then Add component
The bob’s Remote Transform: its turn, and only its turn, onto the hand.
The Remote Transform’s Target
The Remote Transform’s Target: the node it copies its own node onto, by name, anywhere in the scene. The bob’s is clock_hand, the clock face’s child. Empty, or a name nothing answers to, it copies nothing, and the Problems tab says so.
The Remote Transform’s Position
The Remote Transform’s Position: whether it copies its node’s place onto the target. It comes ticked. The bob’s is unticked: ticked, it would put the hand on the bob each step instead of on its hub.
The Remote Transform’s Rotation
The Remote Transform’s Rotation: whether it copies its node’s turn onto the target. It comes unticked. The bob’s is ticked: every step the hand is turned exactly as the bob is, and the bob is turned as far as it has swung, so the hand carries the rod’s line on through the hub.
The Remote Transform’s Scale
The Remote Transform’s Scale: whether it copies its node’s size onto the target. It comes unticked, and the bob’s stays so: the bob is drawn at its own size, so a copy would change nothing. Chapter 14’s tavern sign, drawn larger than its shadow, ticks it.
The Remote Transform’s Offset
The Remote Transform’s Offset: added to a copied Position, in world units, to set the target that far off its node. With Position unticked it does nothing, so the bob’s stays 0, 0. Chapter 14 casts a sign’s shadow onto the wall behind it with one.
The Remote Transform’s Enabled
The Remote Transform’s Enabled: whether it copies right now. It comes ticked, and the bob’s stays so. Unticked, the target stays wherever it was last left. Chapter 14’s tavern sign has a script switch its own on and off, as a lamp beside it is lit and put out.

It swings

  1. Select clock_face. Press F5. While the game runs the Viewport looks through the game camera (Look through on the toolbar), on the knight far below: move the pointer over the Viewport and press F to frame the clock instead.
  2. Click bob in the Hierarchy, under clockworks, so its joint is drawn at full strength. The bob swings west under the hub and back, the rod and the hand turning with it, and it goes on swinging. Press F5 to stop.
Four pictures of the clock face with the pendulum hanging from its hub, the bob selected, a thin blue box turned with it and the word Distance at its rim: the bob pulled out to the lower right, rod and hand in one line up and to the left through the hub, a thin orange line along the rod from the bob’s rim to the hub and an orange cross at each end; the bob straight below the hub, the rod and its orange line straight down and the hand straight up, an orange arrow pointing west from the bob; the bob out to the lower left, the hand leaning up and to the right, the orange line along the rod; and the bob out to the lower right again, as in the first
Steps 0, 21, 42 and 589 of Play (0.00, 0.35, 0.70 and 9.82 s), nothing pressed, bob selected as in the steps above. The bob starts at its east end, passes under the hub on step 21 and turns at its west end on step 42, 53.13° out; on step 589 it is back at its east end, as far out, after seven swings there and back. The hand is turned as the bob in every frame.

The rose box on the bob is its body, its top half, and the orange arrow its Drift: the sideways part of its swing, which chapter 10 reads. The joint’s orange link runs along the rod from the rim to the hub, with its Kind written at the rim: drawn at full strength because bob is selected. Select any other node and it is drawn at half strength, faint on the grey rod.

Along the room’s top run two one-way ledges at one height, out of reach of his jump from the floor: the gallery. The east ledge lies just west of the bob’s far turn; the west ledge lies under H4, the opening up to the next floor. Between them is a break, over gap B in the floor.

  1. Select clockworks, click + Add node and choose Sprite. Rename it gallery_east and set its Position to 264, 988. In its Sprite, drag art/scaffold-plank.png onto Texture and set its Size to 80, 8; choose Tiled in Draw Mode and set Tile Size to 48, 8.
  2. Click Add component and choose ColliderComponent. Set its Size to 80, 8 and tick One Way.
  3. Press Ctrl+D, rename the copy gallery_west and set its Position to 56, 988.
  4. Press Ctrl+S.

The east ledge runs from x 224 to 304, the west one from 16 to 96, both with their tops at 984: 136 over the floor, out of his held jump of 110, and 56 under the ceiling. The break between them, 128 across, sits right over gap B.

Riding it

From where chapter 6 leaves him, the pendulum is the way across gap A and up to the east ledge. It needs a jump timed to the swing: up as the bob starts back toward him, so it comes under him at the top.

  1. Select knight and set his Position to 488, 1120. Press F5.
  2. Hold A and walk him to the edge of gap A; let go there. He stands under the near end of the swing.
  3. Watch the bob swing away west. As it turns at the far side and starts back, jump straight up with Space, held, and let go as he lands: he comes down on the bob’s top as it turns at his side. A jump a little after the turn, not on it: from six to sixteen steps after it, a window about a sixth of a second wide. A miss lands him back at the edge; wait for the next swing and try again. Pause and Step (F6 and F7), with the Play bar’s step counter, show the timing.
  4. Hold nothing. The bob carries him back across the gap to its far turn.
  5. There, hold A and Space together: he jumps west off the bob, his head meets the ceiling, and he lands on the east ledge. Let go.
  6. Press F5 to stop, and set his Position back to 48, 1792.
Four pictures of the clock face and the gap under it: the knight jumping up from the gap’s east edge, a long arrow up, the bob at the lower left starting back toward him; the knight near the top of his jump, the bob swinging under him; the knight standing on the bob’s top at the east end of its swing; and the knight on the bob at the west end of its swing, the hand leaning up and to the right
Steps 54, 70, 82 and 110 of Play (0.90, 1.17, 1.37 and 1.83 s). A held for the first 12 steps walks him to the edge, at 456. The bob turns at its far side on step 42; Space goes down on step 54 and is held until he lands on the bob on step 82, his feet at 1028.5, 18 under the top of his jump. With nothing held it carries him to its west turn, at 328.8, on step 110. For this picture he was started at the skip, 488, 1120.
Five tall pictures of the east ledge and the clock face’s west rim: the knight standing on the bob below the ledge; jumping up and west off it, a long arrow; his head against the ceiling, an arrow pointing west; coming down over the ledge, an arrow pointing down and west; and standing on the east ledge
The same run: A and Space held from step 111, the bob’s far turn, until he lands. Steps 111, 115, 119, 124 and 129 (1.85, 1.92, 1.98, 2.07 and 2.15 s): his head meets the ceiling on step 119, his feet at 958, 26 over the ledge’s top, and he lands on the east ledge at 281.3 on step 129.

Ridden, the bob swings faster: from his side to its far turn, steps 82 to 110 in the ride above, takes about 28 steps, where empty a half-swing takes 42. The bob is pressed by the gravity of what stands on it, and that press adds to its own pull every step he rides it. It still swings 53° each way, his weight and all.

The break, and H4

That is as far as this chapter goes. The break between the ledges is too wide for a jump under a ceiling so close: chapter 8 hangs a chain bridge across it.

  1. Select knight, set his Position to 488, 1120 and press F5. Ride the bob and jump to the east ledge, as above.
  2. Hold A and run off the ledge’s west end, pressing and holding Space as he reaches it: his head meets the ceiling, he comes down well short of the west ledge, and drops through the break and gap B to the ice hall’s floor below. Press F5 to stop, and set his Position back to 48, 1792.
Four tall pictures of the room west of the east ledge, the west ledge’s end at the far left and a brick wall with a lantern below: the knight at the east ledge’s west end, an arrow pointing west; his head at the ceiling over the break; back down at the ledges’ height, still far east of the west ledge, a long arrow down and west; and dropping into the gap in the floor
The same run on: A held from step 140, and Space from step 160, as his box reaches the ledge’s end. Steps 160, 163, 172 and 187 (2.67, 2.72, 2.87 and 3.12 s): his head at the ceiling on step 163; on step 172 his feet are back at the ledges’ height with his box 93.9 east of the west ledge’s end; he lands on the ice hall’s floor on step 201.

To try the west ledge before the bridge reaches it, set him on it.

  1. Select knight and set his Position to 56, 984: on the west ledge, under H4.
  2. Press F5. Hold D and Space together, and let go as he lands: he jumps up through H4 and lands on the floor above, east of the opening. Press F5 to stop.
  3. Set his Position back to 48, 1792.
Five pictures of the west end of the room, the west ledge at the bottom left and the stone slab of the ceiling across the top with an opening at its left: the knight standing on the west ledge; rising into the opening, a long arrow up and east; above the slab, in the room above; at the top of his jump; and standing on the slab’s top, east of the opening
Steps 2, 8, 14, 22 and 31 (0.03, 0.13, 0.23, 0.37 and 0.52 s), D and Space held from step 2 until he lands on step 31. His feet rise to 874, 22 over the floor above, and he lands on it at 133.3. Framed at 128.3%, so the floor above fits. For this picture he was placed on the west ledge at 56, 984.

The clockworks

NodeComponentFieldValue
clockworks(a Node)Position0, 0
clock_facePosition384, 996
SpriteTexture, Sizeclock-face.png; 128, 128
Sort Layer-2
clock_hand(under clock_face)Position, Rotation0, 0; -53.13
SpriteTexture, Sizeclock-hand.png; 8, 64
Anchor, Sort Layer0.5, 0.75; -1
pivot(a Node)Position384, 996
bobPosition, Rotation448, 1044; -53.13
SpriteTexture, Sizependulum-bob.png; 32, 32
Sort Layer2
Character BodySize32, 16
Driven ByScript, no script
ColliderKind, SizeCircle; 32, 32
Step4
JointKindDistance
Targetpivot
Anchor0, -16
Target Anchor, Length0, 0; 64, as they come
Turns Bodyticked
Enabled; Use Limitsticked; unticked, as they come
Remote TransformTargetclock_hand
Position; Rotationunticked; ticked
Scale; Offset; Enabledunticked; 0, 0; ticked, as they come
rod(under bob)Position0, -16
SpriteTexture, Sizependulum-rod.png; 6, 64
Anchor, Sort Layer0.5, 1; 1
gallery_eastPosition264, 988
gallery_westPosition56, 988
each ledgeSpriteTexture, Sizescaffold-plank.png; 80, 8
Draw Mode, Tile SizeTiled; 48, 8
ColliderSize80, 8
One Wayticked

Every node here is under clockworks but the hand, under clock_face, and the rod, under bob. Every other field is as it comes.

Check it works