Skip to content

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.

  • 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.

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.

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.

  1. 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.

  2. On the camera, add a First Person controller, then a Character Controller. Set the Character Controller’s center to { 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.

  3. Add a Spawn Point entity where the player should start, facing the way they should look.

  4. On the camera, add a Signal Emitter with the signal player, and a Camera Impact effect.

  5. 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 });
    }
    });
    }
  6. Enter play. Walk, jump, and watch the view dip each time you land.

  • self.parent is the camera the Behavior sits under; its Camera Impact effect is looked up once in startup.
  • The Character Controller sends CharacterController::state-change through the camera’s Signal Emitter, with the new state and the previous one. Leaving fall means the character just landed.
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
GlobalWhat it is
CharacterControllerComponentThe 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.
TeleportComponentPoint-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.
ComponentTypeWhat it does
Teleportcomp-teleportPoint and teleport with an aiming arc.
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.