# 3D platformer kit

> Turn on platformer movement, a follow camera, lives and checkpoints, and build levels from moving platforms, springs, hazards, enemies and power-ups.

Source: https://feather-engine.com/docs/gameplay/platformer/

The platformer kit turns the player into a platform-game character. It replaces walking with
tight, tunable movement: a jump that goes higher the longer you hold it, chained double and triple
jumps, long jumps, backflips, wall jumps, a ground pound and a dive. A fixed-angle or side-on camera
follows the player, and the kit adds lives, a kill height and respawning at checkpoints.

Levels are built from ordinary objects with a **Platform** component: platforms that move along a
path, fall or spin, springs, checkpoints, goals, hazards, enemies to stomp, power-ups, extra lives
and stars. The kit is off until a project turns it on, and all of it is project data, edited in the
editor or through `platformer.get`, `platformer.set` and `scene.update`.

## What's included

- **Movement:** acceleration and skids, a variable-height jump, coyote time and jump buffering,
  double and triple jumps, extra air jumps, long jump, backflip, wall slide and wall jump, ground
  pound and dive.
- **Moving platforms** that carry whoever stands on them; jumping off keeps their momentum.
- **Level pieces:** path movers, falling platforms that come back, spinning pieces, springs,
  walkers that patrol or chase, and roles: checkpoint, goal, hazard, enemy, power-up, extra life
  and star.
- **Camera:** a fixed-angle follow camera the player can turn in steps, a side-on camera, or the
  normal orbit, with camera zones that change the framing per area.
- **Rules:** lives, a kill height, respawning at the last checkpoint, a short invulnerability after
  a hit, and a life for every 100 coins.
- **Power-up forms** that change size, speed and jump, add a glide or wall climb, or throw
  fireballs. A hit takes the form away instead of a life.
- A drop shadow under the player, sounds for every move and event, and script functions and events.

## Turn it on

1. Open **Window → World & terrain** and select the **Player** tab.
2. Expand the **Platformer** section and turn on **Enabled**.
3. Tune the movement, rules and camera in the same section.
4. Press **Play**.

| Control | Move |
| --- | --- |
| Hold **Jump** | Jumps higher the longer it is held |
| **Jump** again just after landing, while running | Double jump, then a triple jump |
| **Sprint** | Runs at the dash speed |
| **Crouch** + **Jump** while running | Long jump |
| **Crouch** + **Jump** standing still | Backflip |
| Push into a wall while falling | Wall slide; **Jump** kicks off |
| **Crouch** in the air | Ground pound |
| Left mouse button in the air | Dive; with a fireball form it throws a fireball instead |
| **Q** and **E** | Turn the fixed camera by its turn step |

Movement is relative to the camera: pushing up the screen moves away from it. The kit doesn't take
over while the player swims.

### Movement

| Setting | Field | Range | Default |
| --- | --- | --- | --- |
| Run speed | `run_speed` | 1–30 m/s | 8 m/s |
| Dash speed | `dash_speed` | 1–40 m/s | 11.5 m/s |
| Ground acceleration | `ground_accel` | 1–300 m/s² | 45 m/s² |
| Ground braking | `ground_decel` | 1–300 m/s² | 55 m/s² |
| Skid braking | `skid_decel` | 1–400 m/s² | 90 m/s² |
| Air acceleration | `air_accel` | 0–200 m/s² | 24 m/s² |
| Air braking | `air_decel` | 0–100 m/s² | 4 m/s² |
| Turn rate | `turn_rate` | 1–60 rad/s | 14 rad/s |

### Jumping

| Setting | Field | Range | Default |
| --- | --- | --- | --- |
| Jump speed | `jump_speed` | 1–40 m/s | 13 m/s |
| Jump cut | `jump_cut` | Upward speed kept when Jump is let go early, 0–1 | 0.45 |
| Rising gravity | `rise_gravity` | 1–200 m/s² | 34 m/s² |
| Falling gravity | `fall_gravity` | 1–300 m/s² | 60 m/s² |
| Apex gravity | `apex_gravity` | Gravity near the top of a held jump, 0.1–1× | 0.55× |
| Apex window | `apex_window` | Vertical speed below which apex gravity applies, 0–10 m/s | 2.5 m/s |
| Max fall speed | `max_fall` | 1–100 m/s | 30 m/s |
| Coyote time | `coyote` | Jump still works after running off a ledge, 0–0.5 s | 0.1 s |
| Jump buffer | `jump_buffer` | A Jump pressed just before landing is kept, 0–0.5 s | 0.13 s |
| Triple jump | `triple_jump` | On/off | On |
| Chain window | `chain_window` | 0–1 s after landing | 0.22 s |
| Chain needs speed | `chain_min_speed` | 0–20 m/s | 3.5 m/s |
| Second jump speed, Third jump speed | `second_jump`, `third_jump` | 1–40 m/s, 1–50 m/s | 15 m/s, 18 m/s |
| Air jumps | `air_jumps` | Extra jumps in the air, 0–5 | 0 |
| Air jump speed | `air_jump_speed` | 1–40 m/s | 11 m/s |

### Special moves

| Setting | Field | Range | Default |
| --- | --- | --- | --- |
| Long jump | `long_jump` | On/off | On |
| Long jump forward, up | `long_jump_forward`, `long_jump_up` | 1–40 m/s, 1–30 m/s | 15 m/s, 8 m/s |
| Long jump needs speed | `long_jump_min_speed` | 0–20 m/s | 4 m/s |
| Backflip | `backflip` | On/off | On |
| Backflip up, back | `backflip_up`, `backflip_back` | 1–50 m/s, 0–20 m/s | 17 m/s, 3.5 m/s |
| Wall jump | `wall_jump` | On/off | On |
| Wall slide speed | `wall_slide_speed` | 0–20 m/s | 3.5 m/s |
| Wall jump up, out | `wall_jump_up`, `wall_jump_out` | 1–40 m/s, 0–30 m/s | 13 m/s, 8 m/s |
| Wall jump lockout | `wall_lockout` | Weak air control after a wall jump, 0–1 s | 0.22 s |
| Ground pound | `ground_pound` | On/off | On |
| Pound hang, speed | `pound_hang`, `pound_speed` | 0–1 s, 5–80 m/s | 0.22 s, 32 m/s |
| Dive | `dive` | On/off | On |
| Dive forward, up | `dive_forward`, `dive_up` | 1–40 m/s, 0–20 m/s | 13 m/s, 5 m/s |
| Stomp bounce | `stomp_bounce` | 0–40 m/s | 10 m/s |
| Stomp bounce (Jump held) | `stomp_bounce_held` | 0–50 m/s | 15 m/s |

### Lives and rules

| Setting | Field | Range | Default |
| --- | --- | --- | --- |
| Lives | `lives` | 0–99; 0 is unlimited | 3 |
| Kill height | `kill_height` | Falling below it loses a life, −10,000–10,000 m | −40 m |
| Respawn delay | `respawn_seconds` | 0–10 s | 1 s |
| Invulnerable after a hit | `invulnerable_seconds` | 0–10 s | 1.5 s |
| Coins per life | `coins_per_life` | 0–10,000; 0 never gives a life | 100 |
| Drop shadow | `drop_shadow` | A round shadow under the player | On |

A hit from a hazard or an enemy takes away the player's power-up form if they have one, and
otherwise costs a life. A fall below the kill height always costs a life. The player respawns at
the last checkpoint, or at the player start. When the last life is lost, the game sends
`platformer:game_over` and the player starts again with a full set of lives from the player start.
Coins are the collectible score: objects with **Behaviours → Collectible** add to it (see the
coin example in [Scripting](/docs/logic/scripting/)).

### Camera

| Setting | Field | Range | Default |
| --- | --- | --- | --- |
| Style | `camera.style` | `Fixed`, `SideScroll`, `Orbit` | Fixed |
| Yaw | `camera.yaw` | −360–360°; 0 looks toward −Z | 0° |
| Pitch | `camera.pitch` | 0–89° | 32° |
| Distance | `camera.distance` | 2–80 m | 13 m |
| Aim height | `camera.height` | 0–10 m above the feet | 1.2 m |
| Follow | `camera.follow` | 0.5–30; higher is tighter | 5 |
| Look ahead | `camera.look_ahead` | Seconds of the player's velocity, 0–2 s | 0.25 s |
| Field of view | `camera.fov` | 0–120°; 0 keeps the project's | 0° |
| Turn step | `camera.turn_step` | 0–180°; 0 stops the player turning it | 45° |

**Orbit** keeps the normal third-person camera. The camera follows the player's height only while
they stand, or when they move far above or below it, so it doesn't bob on every jump.

**Camera zones** (`camera_zones`) are boxes with their own camera. Each has a unique `name`, a
`center`, a `size` (0.1–10,000 m per axis, default 10 m), a `camera` with the fields above, a
`blend` time (0–5 s, default 0.8 s) and a `priority` (−100–100); where zones overlap, the higher
priority wins. Up to 256 zones.

### Power-up forms

Forms (`forms`) are listed by name and given by power-up pieces. Up to 32.

| Field | Description | Range | Default |
| --- | --- | --- | --- |
| `name` | Unique, 1–48 characters | — | — |
| `scale` | Body size, × the avatar's | 0.2–4 | 1 |
| `speed`, `jump` | Run and jump speed, × | 0.2–3 | 1 |
| `glide` | Holding Jump while falling floats down no faster than this; 0 is no glide | 0–20 m/s | 0 |
| `climb` | Pushing into a wall in the air climbs it at this speed; 0 is no climbing | 0–20 m/s | 0 |
| `climb_seconds` | Longest climb before sliding back | 0–10 s | 1.2 s |
| `fireballs` | Attack throws bouncing fireballs that defeat enemies | On/off | Off |

Up to two fireballs fly at once. They bounce along the ground, burst on walls and defeat the first
enemy they touch.

### Sounds

`sounds` names a sound or cue for each move and event: `jump`, `double_jump`, `triple_jump`,
`long_jump`, `wall_jump`, `pound`, `land`, `coin`, `stomp`, `spring`, `power_up`, `power_down`,
`death`, `checkpoint`, `goal`, `extra_life`, `star` and `fireball`. Empty plays nothing.

## Build a level with platform pieces

1. Select an object and click **Add Component → Platform** in the Details panel.
2. Pick a **Role**, or leave it on **None** for a plain moving or falling platform.
3. For a moving platform, click **+ Point** to add path points, in metres from where it starts, then
   choose a **Mode**, **Speed** and **Wait at points**. Turn on **Start when stood on** to keep it
   still until the player lands on it.
4. Give moving pieces a **Kinematic** body (or none). Kinematic bodies must be root objects.
5. Set **Spin °/s**, **Falls after standing** or **Spring bounce** as needed.

| Setting | Field | Range | Default |
| --- | --- | --- | --- |
| Path | `path` | Up to 64 points, each within 10 km of the start | None |
| Mode | `mode` | `loop`, `ping_pong`, `once` | loop |
| Speed | `speed` | 0.05–100 m/s | 3 m/s |
| Wait at points | `wait` | 0–60 s | 0.5 s |
| Start when stood on | `on_touch` | On/off | Off |
| Falls after standing | `fall_after` | 0–60 s; 0 never falls | 0 s |
| Comes back after | `respawn` | 0–600 s; 0 is gone for good | 3 s |
| Spring bounce | `bounce` | Launches the player up at this speed, 0–80 m/s | 0 |
| Spin °/s | `spin` | Degrees per second around x, y, z, up to ±3600 | 0, 0, 0 |
| Walk | `walk` | Walks along the ground, turning at ledges and walls, 0–30 m/s | 0 |
| Chase | `chase` | A walker heads for the player within this distance, 0–200 m | 0 |
| Role | `role` | See below | `none` |
| Form | `form` | The form a `power_up` gives | — |

Paths ease in and out at each point, so riders aren't jolted, and riders turn with spinning pieces.
The Details panel's sliders cover part of some ranges; use `scene.update` for the rest, and for
`walk`, `chase` and the roles not in the panel's list.

| Role | When the player touches it |
| --- | --- |
| `checkpoint` | Sets where the player respawns |
| `goal` | Finishes the level and sends `platformer:goal`, once |
| `hazard` | A hit |
| `enemy` | Landing on top squashes it with a bounce; touching it from the side is a hit |
| `power_up` | Gives its `form`, which must be one of the forms |
| `extra_life` | Gives a life |
| `star` | A big collectible, counted and sent as `platformer:star` |

Enemies, power-ups, extra lives and stars disappear when they are used. Stop puts every piece back,
and resets lives, forms and checkpoints.

## Example: a spring on the jetty

You'll turn **Ocean Voyage** into a platformer and put a spring on the jetty, 3 m in front of the
player start.

1. Open **Window → World & terrain → Player**, expand **Platformer** and turn on **Enabled**.
2. Under **Camera**, set **Yaw** to `180`, so the camera looks along the jetty and **W** runs out to
   sea.
3. Click **Add → Cube** in the toolbar and rename it `Spring`. Under **Transform**, set **Parent**
   to **Jetty**, **Local location** to `0`, `0.55`, `5` and **Scale** to `2`, `0.1`, `2`.
4. Under **Physics**, set **Body** to **Static**.
5. Click **Add Component → Platform** and set **Spring bounce** to `20` m/s.
6. Press **Play** and run forward onto the spring.

Do the same from the command line, on a copy of the example. `scene.add` returns the new object's
ID; in a fresh copy of Ocean Voyage it is 36.

```bash
cp -R examples/ocean-voyage /tmp/demo

feather-cli --workspace /tmp/demo --project project.feather.json command platformer.set \
  --json '{"patch":{"enabled":true,"camera":{"yaw":180}}}' --save project.feather.json

feather-cli --workspace /tmp/demo --project project.feather.json command scene.add \
  --json '{"kind":"Cube","name":"Spring","parent_id":3,"position":[0,0.55,5]}' --save project.feather.json

feather-cli --workspace /tmp/demo --project project.feather.json command scene.update \
  --json '{"id":36,"patch":{"scale":[2,0.1,2],"physics":{"body":"Static"},"platform":{"bounce":20}}}' \
  --save project.feather.json
```

**Check it worked.** In Play, landing on the spring throws the player several metres up, with the
spring sound if `sounds.spring` names one. `game.simulate` doesn't run the platformer kit; a
real-window run does. A `--verify-run` report from `feather-player` (see
[Profiler](/docs/shipping/profiler/)) has a `platformer` section with the move state, lives,
deaths, respawns, stomps, checkpoints, goals, stars and a count of every jump, bounce and landing.

## Extend it

| Function | Description |
| --- | --- |
| `lives()`, `set_lives(n)` | Read or set the lives, 0–999 |
| `respawn_player()` | Respawns the player at once |
| `set_checkpoint(vec3)`, `checkpoint()` | Set or read the respawn point; `checkpoint()` is `()` when there is none |
| `launch_player(vec3)` | Sets the player's velocity, up to 200 m/s: springs, cannons |
| `player_mode()` | `ground`, `air`, `long_jump`, `backflip`, `wall_slide`, `pound` or `dive` |
| `player_velocity()` | The player's velocity as a vector |
| `player_form()`, `set_form(name)` | Read or set the form; `""` is the base form |
| `score()` | The collectible score this Play session |

| Event | Data |
| --- | --- |
| `platformer:checkpoint`, `platformer:goal`, `platformer:stomp`, `platformer:extra_life` | `id`, `name` |
| `platformer:star` | `id`, `name`, `stars` (the count so far) |
| `platformer:power_up` | `id`, `name`, `form` |
| `platformer:power_down` | `form` |
| `platformer:defeat` | `id` (an enemy hit by a fireball) |
| `platformer:died` | `cause` (`fell`, `hazard` or `enemy`), `lives` |
| `platformer:respawn`, `platformer:game_over` | — |

```rust
// A world script: a cannon that fires the player across a gap, and a goal that ends the level.
fn on_key(key) {
    if key == "C" && player_mode() == "ground" {
        launch_player(vec3(0.0, 18.0, 12.0));
    }
}

fn start() {
    on("platformer:goal", |d| {
        toast("Level complete with " + lives() + " lives left");
    });
}
```

## Limits

- Up to 256 camera zones and 32 forms.
- Up to 64 path points per piece.
- Moving pieces need a Kinematic body or none, and Kinematic bodies can't be group children.
- **Q** and **E** turn only the **Fixed** camera style.

## Automate it

```bash
# Turn the kit on with a double jump and five lives
feather-cli command platformer.set \
  --json '{"patch":{"enabled":true,"air_jumps":1,"lives":5}}'

# A fire form and a gliding form, and a side-on camera inside a tower
feather-cli command platformer.set \
  --json '{"patch":{"forms":[{"name":"fire","fireballs":true},{"name":"glider","glide":3}],"camera_zones":[{"name":"tower","center":[0,10,0],"size":[12,30,12],"camera":{"style":"SideScroll","distance":18},"blend":1.2}]}}'

# Object 40: a platform that goes 6 m out and back, pausing 1 s at each end
feather-cli command scene.update \
  --json '{"id":40,"patch":{"physics":{"body":"Kinematic"},"platform":{"path":[[0,0,-6]],"mode":"ping_pong","speed":2,"wait":1}}}'

# Object 41: a power-up that gives the fire form
feather-cli command scene.update \
  --json '{"id":41,"patch":{"platform":{"role":"power_up","form":"fire"}}}'
```

`platformer.get` returns every setting. `platformer.set` patches merge, but `forms` and
`camera_zones` are replaced as a whole.
