logo

Babylon.js Market

PlayerWalkAnimator

shooter

PlayerWalkAnimator

Listens toHealth
1
Locomotion RiggerBonus figureLocomotion Rigger
Unlock

Install with the CLI:

bjs download PlayerWalkAnimator

PlayerWalkAnimator

Gates a player's locomotion clip on actual movement, freezing the skeleton when the player stops and playing a one-shot death clip on death.

What it does

The Commando-style player GLB has no idle clip, so its locomotion is driven entirely by whether it's moving. Each frame the PlayerWalkAnimatorSystem reads the player's MeshPrimitive proxy position and diffs it against last frame; the moment XZ displacement crosses moveEpsilon it emits SkeletonAnimatorInputEvents.SET_LOOP with walkClip, and the moment the player stops it emits SET_LOOP '' — which halts the clip and freezes the skeleton on its last frame. It also listens for HealthEvents.DIED (fires deathClip as a held one-shot via PLAY_ONCE) and HealthEvents.RESPAWNED (re-baselines movement state so the instant teleport isn't read as a step). It's the player-side equivalent of EnemySystem's animation glue, and is renderer-agnostic — it talks only through the EventBus.

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 PlayerWalkAnimator

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 PlayerWalkAnimator
    bjs download PlayerWalkAnimator

    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],
        "visible": false
      },
      "Mesh": {
        "src": "/shooter/Commando-shooter.glb",
        "instanced": true,
        "follow": true,
        "faceMode": "proxy",
        "lockRootMotion": true
      },
      "SkeletonAnimator": {},
      "PlayerWalkAnimator": { "walkClip": "Run_and_Shoot", "deathClip": "Fall_Forward" }
    }
  }
}

Props

  • walkClip (string, default 'Walking') — loop clip played while the player is moving.
  • deathClip (string, default 'Fall_Forward') — one-shot clip played on HealthEvents.DIED, held on its final frame.
  • moveEpsilon (number, default 1e-3) — minimum per-frame XZ displacement (world units) that counts as "moving"; below it the player is treated as stopped and the clip freezes.

Events

  • Emits SkeletonAnimatorInputEvents.SET_LOOP on every move/stop transition (walkClip when moving, '' to freeze) and on first frame to assert the idle state.
  • Emits SkeletonAnimatorInputEvents.PLAY_ONCE (clip: deathClip, hold: true) when the player dies.
  • Listens for HealthEvents.DIED (play the death clip) and HealthEvents.RESPAWNED (re-baseline movement state).

Dependencies

Health — supplies the DIED / RESPAWNED events that drive the death clip and respawn re-baselining. MeshPrimitive — its proxy position is the movement signal that gates the loop. SkeletonAnimator — the actual animator this component drives via SET_LOOP / PLAY_ONCE.

Notes

  • Movement is detected off the MeshPrimitive proxy (the invisible capsule another system, e.g. TwinStickShooter, moves each frame) — not off the visible mesh; the player needs both components.
  • SET_LOOP is emitted only on transitions, not every frame; SET_LOOP '' is a safe no-op that freezes rather than restarting.
  • After death the System does not auto-resume a loop — the model holds its fallen pose until the next move re-triggers walkClip. The death/respawn handlers are guarded to entities carrying this component, so enemy deaths (handled by EnemySystem) are unaffected.
  • Per-entity movement state lives on the System (keyed by entity id), never on the Component, because it isn't serializable.

More like this

Health
MeshPrimitive
SkeletonAnimator
AiPilot
AnimateMeshy
Animation
ArcCamera
Asteroid
Bullet
CameraFollow
DirectionalLight
Enemy
EnemySpawner
EnvironmentTexture
FreighterCar
FreighterChain
FreighterHead
GameConfig
HemisphericLight
Jump
KeyboardInput
KeyboardMover
Lifetime
LineOfSight
MachineGun
Mesh
Missile
MissileLauncher
MissionDirector
MoneyField
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PlayerInput
RespawnTimer
Score
Shadow
ShipLoadout
ShooterCamera
SpaceShooterBullet
SpaceShooterHealth
SpaceShooterScore
TwinStickShooter
WaveDirector
Waypoint
WaypointTrack

Was this page helpful?

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

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search