◀ 7.27.37.4 ▶

7.3 — Ladders I: The Climbing State

Go and look for a ladder. Search the project for a sprite, a tile, a prefab, an animation clip — search the word itself. The word finds nothing, and that is the trap: there is no ladder prefab, no climb animation and no Ladder tag anywhere here. There is art, sliced into the cave tileset and filed under a number. So the ladder splits in two: a look you paint from tiles you already know (7.1), and a mechanic — a state in which the character may ignore gravity. The mechanic is the work.

In this lesson you will be able to answer“how do I climb a ladder?”Outline only
Break It Down~10 minOutline only

Make the character climb. A ladder is not a thing you collide with — it is a place where the normal rules stop applying for a while. So the whole feature is: build a volume that knows you are inside it, let that knowledge change what gravity and your input mean, and then put everything back exactly as it was the moment you step off.

First, before any code: cut that into parts small enough that you could look each one up on its own.

  1. Cut a zone the trigger can seewhat does this part do?Read: the trigger-versus-collision split from 2.1, and the tag ritual you performed on the potion in 2.3
  2. Turn the zone's two messages into one flagwhat does this part do?Read: the coin's OnTriggerEnter2D in 2.1, and the bool you declared for the first time in 5.1
  3. Take gravity away while the flag is upwhat does this part do?Read: the gravityScale branch in 6.3, and the rb.gravityScale row of the Unity + C# Quick Reference
  4. Read the vertical stick, ignore the sideways onewhat does this part do?Read: the movement method you settled on in 2.2, and the input axes from 1.4
  5. Decide which gravity rule gets to winwhat does this part do?Read: the FixedUpdate() gravity branch in 6.3, and the frame-versus-physics-step split from 1.3

The split is not five equal problems. Four of them are shapes you have already typed: a trigger that reports a tagged object (2.1), a bool that remembers something (5.1), a movement line that writes linearVelocity (2.2), and a gravity branch (6.3). Only one idea here is new, and it is the reason the lesson exists. Until today every value in your script described how much — a speed, a force, a fall multiplier. The climb flag describes which rules apply, and it changes the meaning of two numbers you already own without touching either of them. That is what a state is, and it is why the last part of the split is an argument about order rather than a line of code.

The test: could you look this part up on its own, right now, in one search? "Make the player climb a ladder" cannot be looked up. "Set gravityScale to zero while a bool is true" can — and the page you land on also tells you which body type it applies to, and what a Static body does with the number instead. If a part is small enough to search for, the split is finished.

Your turn

Pick two of the parts above and say in one line what each one actually does.

Name the single number the climb and the fall-speed rule both want to own, and say which piece of code writes it last. Then say what the player sees when you get that order wrong.

The climb throws the sideways input away. Name a moment in your own level where that would be the wrong call, and say what the player would feel instead.

Your jump is an impulse — one flick of force — and the climb writes a velocity. Say why an impulse is the wrong tool on a ladder.

In the Editor ~25 min

Confirm the situation before you design around it. Project window → search ladder, then climb; Project window → Assets/Artwork/Character/Player/ → open the Player's Animator controller and read its states. Four things to check, and the first is why this page has a trap in it:

What you might expect to findWhat is actually there
A ladder sprite or tile It is there, and it is numbered. MainLev2.0.png is sliced into 1,829 tiles called MainLev2.0_0 through MainLev2.0_1828, so the word "ladder" is printed on none of them. The rung column is MainLev2.0_1375 (the head) with _1422, _1468 and _1514 below. This is 7.1's lesson in one search: the art exists, the name does not.
A ladder prefab Nothing. The project's prefabs are the Player, Coin, Spikes, Axe Item, Switch, Turret, Turret Projectile and Mobile Enemy.
Climb frames on the character Nothing. The Player's controller holds three motions — Idle, Walk and Shovel_Swing — each in Up, Horizontal and Down variants. No climb state, no climbing poses in any character sheet.
A "Ladder" tag Nothing. The tags are Coin, Enemy, Axe, Spikes, Ground and GroundCheck.

So the ladder is yours to build, and it splits cleanly in two. The look is a painting problem and you have a tileset. The mechanic is the part that has never existed here: a state your player can be in that is neither walking nor falling, entered only because a trigger said so.

Movement stateGravityWhich input drives itWhat it looks like
Top-down (Overworld, 5.3) None — the world has no down WASD, four directions The Walk states, driven by WalkDir
Grounded (Platformer, 6.1) Tuned with gravityScale A/D sideways, Space to jump Idle or Walk, driven by IsWalking
Climbing (new today) None — the ladder owns gravity W/S only; sideways is ignored Whatever you decide — see 7.4. A held pose is honest for now.
Airborne (6.2, 6.3) Tuned, with the fall multiplier Limited — mostly your own momentum Nothing dedicated; the character just moves

Build the clicks first. Every step names its pane; the third is a real design decision, so read all three options before choosing.

  1. Window ▸ 2D ▸ Tile Palette → open the Caves palette from 7.1 and drag three rungs into it from CavesTileSet/: MainLev2.0_1422, _1468 and _1514. The head, MainLev2.0_1375, is already in the tray — put it on top and you have a four-tile ladder. Scene view → paint it one tile wide, floor to ledge. Invent your own from the vine tiles if you like: the mechanic does not care what the picture is, which is why the picture is the small half of this problem.
  2. Hierarchy → create an empty GameObject over the strip and name it something you would want to find in three weeks. Inspector → give it a Box Collider 2D with Is Trigger ticked, sized to the strip's full height. Then Edit ▸ Project Settings ▸ Tags and Layers → create a Ladder tag — the ritual from the potion in 2.3 — and assign it.
  3. Inspector → the zone → decide which tilemap the picture lives on, and defend it. Three options, and they are not equivalent:
Where you paint itWhat happens when you climbThe cost
On No Collision, the picture-only tilemap The player passes cleanly through and rises the whole height. Simplest possible interaction. The ladder is not solid at all — the player can also walk through it sideways at the bottom.
On a new tilemap child (renderer only, no collider), so the ladder art groups and can be found later Same as above, but the ladder is a named object you can select and reuse. One more tilemap to track, and you must remember it has no collider.
On Collision, the solid tilemap, with the zone in front of it The player is stopped by their own ladder and cannot climb it at all. Fatal as described — unless you leave a one-tile channel beside it, which changes the level.
In the Code ~35 min

The code is the smallest script in the unit. Answer the two specifications in writing first: they are the whole design, and the code afterwards is transcription.

Architectural specification: the ladder zone.
  • What does the zone carry that lets your script recognise it? Need a new tag, or can you reuse one of the six? If a new one, name it exactly.
  • Which two messages does the zone send, and what type is the parameter each hands you?
  • Is the zone a trigger or a solid? What happens to the player if you forget that checkbox — and would any error message tell you?
  • Which single field on the player does the zone write? Name it and name everything that reads it — a flag read by nobody is decoration.
  • The zone is invisible. What is the player actually looking at when they decide to climb?
Architectural specification: the climb state.
  • What is climbSpeed, what type is it, how is it exposed as a tuning knob, and why slower than walking?
  • Which component's gravity is switched off, and to what value? Where does the number come from when you switch it back on — a literal you type, or a value you cached in 6.3? Justify your answer.
  • 6.3 already assigns gravityScale on the physics clock, once per physics step, from your vertical velocity. If your climb branch sets it to zero in Update() and 6.3's branch sets it back, which wins? Predict, test, describe the symptom.
  • Your movement is the method you settled on in 2.2 — linearVelocity on a Dynamic body. What does it need in order to move the player straight up a ladder, and why does that velocity line carry no Time.deltaTime?
  • What exits the climb state? List them — the top, jumping, dying, leaving the zone — and say which happen through the trigger and which need handling by hand.
  1. Project window → PlayerController → add the flag and the speed knob, then write the two callbacks the zone sends. This is four lines of behaviour, and the whole difficulty is in the else branch where you restore gravity. Do that first, before any climbing movement, and test it: Game view → press Play, walk into the zone, and confirm the flag flips by printing it with Debug.Log(). The HUD from 5.3 lives in Start (index 0) and reads only your stats — it is not in this scene, so a climbing experiment reports through the Console.
  2. Same file → the Platformer branch of Update() → add the climb lane: gravity off, vertical input read, sideways ignored, movement done by the method you chose in 2.2. Press Play and climb. Then let go and watch — and be honest about whether the result is what you intended.
The bug you are about to create, and the two ways out. Jump off the ladder while your body is still inside the trigger. You clear the flag by hand so you can jump — but you never left the zone, so it never sends its exit message. Land, step back on, and nothing happens: the ladder is dead precisely where it used to work. Two standard repairs; pick one and justify it:
  • A cooldown. Ignore the zone for a fraction of a second after a deliberate exit. Simple, and it stops a jump from instantly re-grabbing the ladder.
  • Trust only the zone. Never set the flag by hand: let the exit message be the only thing that clears it, and gate the jump on isOnLadder && jumpPressed. Cleaner in principle; the jump feels one frame late.
Whichever you pick, write down what the player feels.

Socratic: What Kind of Thing Is a Ladder?

  1. The ladder has art, but no prefab, no climb animation and no tag. Which of those four is a painting job and which one is the engineering — and why does the art being nearly free not make today easy?
  2. The trigger zone sets a flag on entry and clears it on exit. The lever from 5.2 flips a value and keeps it forever. Why is a ladder remembered only while you are inside it, and a lever remembered permanently?
  3. Climbing turns gravity off. Your character also had gravity at zero in the Overworld, in 5.3. One number, two meanings, two scenes. What does each mean — and why is "gravity zero" a fact about the state rather than about the world?
  4. Your jump is an impulse and gravity was tuned in 6.1 to make the arc feel right. If the climb sets gravityScale to zero and restores it, what is the danger of restoring a number you typed rather than the one you saved?

Checkpoint — before moving on, you must be able to:

Reference Docs

Need a deeper explanation? These pages cover the same concepts:

Next: 7.4 — Ladders II: Mounts, Tops & Polish.

0/8 answered

Answers save on this device as you type. At the end of class, click Download and upload the file to the Canvas assignment.

Saved on this device only — the Dashboard tracks your progress.