logo

Babylon.js Market

Jump

movement

Jump

Listens toKeyboardInput
Free

Install with the CLI:

bjs download Jump

Jump

A scripted vertical jump arc on a keypress — rise, hang, fall, land exactly where you left.

What it does

Jump is data-only: it holds a key, a peak height, an air-time duration, and a hang factor. The System listens for keyboard.keydown and for a jump.request event; on the configured key it starts a jump, captures the entity's current ground Y, and emits jump.started carrying the duration and height. Each frame while airborne it advances elapsed, computes progress p = elapsed / duration, and writes the vertical offset groundY + height * arc(p) back onto the entity — a followed Mesh's Y if the entity has one, otherwise the MeshPrimitive proxy's Y. When p reaches 1 it snaps back to the captured ground height and emits jump.landed. The arc is 4p(1-p) (a plain parabola) blended toward sin(πp) by hang, so it always peaks at height when p = 0.5 and is symmetric — ascent and descent mirror, which lets a jump animation's midpoint line up with the apex. Only one jump runs at a time: a key-repeat or a second press mid-air is ignored (no double-jump).

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.

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

    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": {
    "components": {
      "MeshPrimitive": { "primitive": "capsule", "height": 1.8, "position": [0, 0.9, 0] },
      "KeyboardMover": { "speed": 4 },
      "Jump": {
        "key": "Space",
        "height": 1.6,
        "duration": 0.7,
        "hang": 0.35
      }
    }
  }
}

Props

  • key (string, default "Space") — the KeyboardEvent.code that triggers a jump. The System matches this against incoming keyboard.keydown events.
  • height (number, default 1.6) — peak height in world units at the apex (p = 0.5), independent of hang.
  • duration (number, default 0.7) — total air time in seconds (ascent + descent). Carried in jump.started so an animator can sync a clip to it.
  • hang (number, default 0.35, clamped to [0, 0.9]) — apex dwell. 0 is a plain parabola; toward 0.9 flattens the top so the character floats at the peak (a game-y, less physical feel).
  • airborne (boolean, default false) — runtime state owned by the System; true while a jump is in progress. Not config.
  • elapsed (number, default 0) — runtime state owned by the System; seconds into the current jump. Not config.

Events

  • emits jump.started (JumpEvents.STARTED) the frame the character leaves the ground, with { entityId, duration, height }.
  • emits jump.landed (JumpEvents.LANDED) the frame the character lands, with { entityId }.
  • listens for keyboard.keydown (KeyboardInputEvents.KEYDOWN, payload { code }) and starts a jump on any matching-entity whose key equals code.
  • listens for jump.request (JumpInputEvents.JUMP, payload { entityId? }) and jumps that entity; a request with no entityId jumps nobody.

Dependencies

None declared. Jump reads a sibling Mesh or MeshPrimitive for the vertical offset if present but doesn't require either — a keyed jumper with no mesh runs without throwing. Something in the scene must bridge DOM key events onto the bus for the keypress path to fire: KeyboardMover (and other input components) already emits keyboard.keydown, so pairing Jump with a mover gives you a walkable, jumpable character out of the box. Without any bridge, drive it purely through jump.request.

Notes

  • The System prefers a followed Mesh's params.position[1] over the MeshPrimitive proxy — the mesh follow reads that field for its Y (copying only X/Z from the proxy), so writing it lifts the visible figure while the capsule proxy and the camera anchor stay grounded (no jump-bob on the camera).
  • Ground Y is captured at takeoff and restored on landing, so a jumper standing at y = 0.9 returns to 0.9, not a hard 0.
  • Per-entity ground state is cleaned up on landing and on entity removal, so removing an airborne entity mid-jump doesn't leak or throw.
  • The jump is scripted, not physics-integrated: height, duration, and hang fully describe the arc, so it needs no physics engine and won't fight a mover for the transform handle.

More like this

KeyboardInput
AiPilot
Animation
ArcCamera
Asteroid
Bullet
CameraFollow
DirectionalLight
Enemy
EnemySpawner
EnvironmentTexture
FlightIntent
Flipper
FreighterCar
FreighterChain
FreighterHead
GameConfig
Health
HemisphericLight
KeyboardMover
Lifetime
LineOfSight
MachineGun
Mesh
MeshPrimitive
Missile
MissileLauncher
MissionDirector
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PinballBuilderInput
PlayerFlightInput
PlayerInput
PlayerInputBridge
PlayerWalkAnimator
Plunger
PokerInput
RespawnTimer
Score
Shadow
ShipFlight
ShipLoadout
SkeletonAnimator
SpaceShooterBullet
SpaceShooterHealth
SpaceShooterScore
Transform6DOF
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