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.
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.
- 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
- Turn the zone's two messages into one flagwhat does this part do?Read: the coin's
OnTriggerEnter2Din 2.1, and theboolyou declared for the first time in 5.1 - Take gravity away while the flag is upwhat does this part do?Read: the
gravityScalebranch in 6.3, and therb.gravityScalerow of the Unity + C# Quick Reference - 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
- 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.
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 find | What 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 state | Gravity | Which input drives it | What 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.
-
Window ▸ 2D ▸ Tile Palette → open the
Cavespalette from 7.1 and drag three rungs into it fromCavesTileSet/:MainLev2.0_1422,_1468and_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. -
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
Laddertag — the ritual from the potion in 2.3 — and assign it. - Inspector → the zone → decide which tilemap the picture lives on, and defend it. Three options, and they are not equivalent:
| Where you paint it | What happens when you climb | The 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. |
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.
- 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?
- 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
gravityScaleon the physics clock, once per physics step, from your vertical velocity. If your climb branch sets it to zero inUpdate()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 —
linearVelocityon a Dynamic body. What does it need in order to move the player straight up a ladder, and why does that velocity line carry noTime.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.
-
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 withDebug.Log(). The HUD from 5.3 lives inStart(index 0) and reads only your stats — it is not in this scene, so a climbing experiment reports through the Console. -
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.
- 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.
Socratic: What Kind of Thing Is a Ladder?
- 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?
- 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?
- 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?
- Your jump is an impulse and gravity was tuned in 6.1 to make the arc feel right. If the climb sets
gravityScaleto 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:
- Name the four tiles a ladder is cut from, and why searching for "ladder" finds none of them
- Say which ladder tiles were already on the
Cavespalette and which you dragged in - Build a trigger zone with its own tag, and say why it must be a trigger
- Explain climb as a state: gravity off, vertical input only, a deliberate restore
- Say which gravity assignment wins in your build — 6.3's physics-step one or your climb branch — and how you know
- Demonstrate the jump-off re-entry bug and defend the repair you chose
- Explain one input axis serving three meanings, chosen by state
- Commit and push
Reference Docs
Need a deeper explanation? These pages cover the same concepts:
- Unit 7: Level Building & Ladders
- Enemy State Machines — states, all the way down
- Unity + C# Quick Reference — triggers, gravityScale and Rigidbody2D bodies
Saved on this device only — the Dashboard tracks your progress.