Movement
Updated
Players need a way to move through your world. The Character Controller is the player’s body: a capsule that walks, runs, jumps, falls, climbs steps and slides along walls, moved by the keyboard, a gamepad, touch controls or VR thumbsticks. a Teleport lets them aim an arc and jump there. Spawn points that place players when a scene loads, and spot and travel points, click-to-go destinations and portals, are in Navigation. For what the player sees, see Cameras; for characters that move on their own, see Navigation too.
Key concepts
Section titled “Key concepts”- Character Controller: The character’s body. It reads the player’s controls, or it is driven by a script, a NavMesh Agent or a Steering Agent.
- States: What the character is doing: idle, walk, run, jump, fall. The controller reports each change as an event, so scripts and animations can react.
- Teleport: Point-and-teleport with an aiming arc, on desktop and in VR. It lands only on walkable ground.
How it works
Section titled “How it works”Movement has one owner per job, which keeps the pieces from fighting each other:
- The Character Controller moves. It reads the player’s controls (keys, gamepad, a Screen Gamepad on touch screens, VR thumbsticks), or it is driven by a script or a navigation agent.
- Cameras look. A camera controller only ever moves or turns its camera. For first person, put the First Person controller and the Character Controller on the same camera entity. For third person, put the Character Controller on the character and a Third Person controller on the camera, with the character as its
target. - Placement points move the player. Teleports, and the spawn, spot and travel points of Navigation, all place the player by one rule. See Placing the player.
Your first moving player
Section titled “Your first moving player”This walkthrough builds a first-person player that walks with WASD and looks with the mouse, and makes the view dip when the player lands from a jump.
-
Add a Perspective Camera entity. A new camera gets a Main Camera component when its scene has none, so it becomes the player’s view.
-
On the camera, add a First Person controller, then a Character Controller. Set the Character Controller’s
centerto{ x: 0, y: -0.7, z: 0 }so the 1.8 m capsule hangs below the eyes. WASD or the arrow keys now walk, Shift runs and Space jumps. -
Add a Spawn Point entity where the player should start, facing the way they should look.
-
On the camera, add a Signal Emitter with the signal
player, and a Camera Impact effect. -
Add a Behavior entity under the camera with this script:
LandingDip.jx #pragma lifecycle(startup)function startup() {const impact = self.parent.getComponent(CameraImpactEffectComponent);on('player', (event) => {if (event.eventType !== EventType.CharacterController.StateChange) return;// Leaving the 'fall' state means the character just touched the ground.if (event.data.previous === 'fall' && event.data.state !== 'jump') {impact.play(0.4, { x: 0, y: -1, z: 0 });}});} -
Enter play. Walk, jump, and watch the view dip each time you land.
self.parentis the camera the Behavior sits under; its Camera Impact effect is looked up once instartup.- The Character Controller sends
CharacterController::state-changethrough the camera’s Signal Emitter, with the newstateand thepreviousone. Leavingfallmeans the character just landed.
Your first moving player: a first-person camera with a Character Controller walks, runs and jumps; the script plays a Camera Impact each time the character lands.
Click the view to look around with the mouse. Walk with WASD, run with Shift, and press Space to jump: the view dips as you land.
Choosing
Section titled “Choosing”| If you want… | Use… | Read |
|---|---|---|
| A body that walks, runs, jumps and collides | Character Controller | Character Controller |
| Point-and-teleport with an aiming arc | Teleport | Teleport |
| Characters that find their own way | NavMesh Agents and steering | Navigation |
| On-screen sticks for phones | Screen Gamepad | Screen Gamepad |
In scripts
Section titled “In scripts”| Global | What it is |
|---|---|
CharacterControllerComponent | The character: a capsule that walks, runs, jumps, falls, climbs steps and slides along walls, turning to face its travel. Player controls, AI and scripts all move it through this one component; cameras only look. |
TeleportComponent | Point-and-teleport: the player aims an arc and lands the entity this is on, on a surface no steeper than slopeLimit. On desktop the right mouse button aims at the pointer, up to distance away; in VR the right grip aims from the controller and the rig follows. |
Components
Section titled “Components”| Component | Type | What it does |
|---|---|---|
| Teleport | comp-teleport | Point and teleport with an aiming arc. |
In this section
Section titled “In this section”| Topic | Description |
|---|---|
| Character Controller | The walking capsule: props, player controls, move, moveTo, jump, teleport, states and events. |
| Teleport | Point-and-teleport with an aiming arc on desktop and in VR, and its events. |