logo
KeyboardMover

movement

KeyboardMover

Listens toKeyboardInput
Free

Install with the CLI:

bjs download KeyboardMover

KeyboardMover

Camera-relative WASD / arrow-key movement for a MeshPrimitive entity.

What it does

KeyboardMoverSystem walks every entity that carries both KeyboardMover and MeshPrimitive across the XZ plane from held direction keys. It listens for keyboard.keydown / keyboard.keyup on the EventBus to track which of forward/back/left/right are down, then builds the move direction from the camera: it reads the first ArcCamera's basis through getCameraForward / getCameraRight, projects both onto the ground plane, and combines them with the input axes — so "forward" is wherever the view faces and the character always walks away from the viewer on W. Diagonals are clamped to a unit vector, so W+D is no faster than a single key. The new position goes out through setMeshPosition; when faceMotion is on, the mesh yaws to face its direction of travel via setMeshRotation. With no ArcCamera in the scene it falls back to a fixed −X-forward basis.

Use it in a scene

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Fastest path

bjs download scene KeyboardMover

Pulls this exact scene into your project and runs it — no copy-paste. Add --all to grab the components and assets it needs too.

Or build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add KeyboardMover
    bjs download KeyboardMover

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "Player": {
    "tags": ["player"],
    "components": {
      "MeshPrimitive": {
        "primitive": "capsule",
        "radius": 0.5,
        "height": 1.6,
        "position": [0, 0.8, 0]
      },
      "KeyboardMover": { "speed": 4, "faceMotion": true }
    }
  }
}

Props

  • speed (number, default 4) — world units per second at full input.
  • faceMotion (boolean, default true) — when true, the mesh yaws to face its direction of motion.

Events

  • Listens for keyboard.keydown{ code }. KeyW/ArrowUp = forward, KeyS/ArrowDown = back, KeyA/ArrowLeft = left, KeyD/ArrowRight = right.
  • Listens for keyboard.keyup{ code }. Releases the matching direction.

Movement applies directly to the mesh; it emits nothing of its own.

Dependencies

MeshPrimitive — the mesh this system moves and rotates each frame; it's also half the System's query, so an entity without one is never driven. ArcCamera — its live camera handle supplies the forward/right basis that makes movement camera-relative; the System finds the first ArcCamera in the world.

Notes

  • The camera basis is re-read every frame, so movement stays correct while the arc camera orbits mid-run.
  • Y is left untouched — a tilted camera still walks the character flat across the ground, never up or down.
  • A/D stay correct under either renderer: the adapter bakes in its own handedness, so the System never branches on which engine drew the scene.
  • The held-key state lives on the System, not per entity — every moving entity shares the same input, so this drives one player, not independent NPCs.

More like this

ArcCamera
KeyboardInput
MeshPrimitive
AiDriver
AiPilot
Animation
Asteroid
BoatMode
Bullet
CameraFollow
CarDrive
DirectionalLight
EnemySpawner
EnvironmentTexture
FlightIntent
Flipper
FreighterCar
FreighterChain
FreighterHead
GameConfig
Health
HemisphericLight
Jump
Lifetime
LineOfSight
MachineGun
Mesh
Missile
MissileLauncher
MissionDirector
MouseInput
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PinballBuilderInput
PlayerFlightInput
PlayerInput
PlayerInputBridge
PlayerWalkAnimator
Plunger
PokerInput
RespawnTimer
RoundReset
Score
Shadow
ShipFlight
ShipLoadout
SkeletonAnimator
SpaceShooterBullet
SpaceShooterHealth
SpaceShooterScore
TrafficConvoy
Transform6DOF
TwinStickEnemy
Velocity6DOF
WaveDirector
Waypoint
WaypointTrack
WorldOriginAnchor

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search