API

Class PhysicsCharacterController

A physics-driven character controller. Create one with createPhysicsCharacterController; drive it each physics step with PhysicsCharacterController.moveWithCollisions and read back the resolved position with PhysicsCharacterController.getPosition.

Index
acceleration: number = 0.05

Acceleration factor used by calculateMovement. Default 0.05.

characterMass: number = 0

Character mass used when reacting to gravity against dynamic bodies. Default 0.

characterStrength: number = 1e38

Push strength applied to dynamic bodies the character contacts. Default 1e38.

dynamicFriction: number = 1

Dynamic-friction coefficient against surfaces. Default 1.

keepContactTolerance: number = 0.1

Extra distance over which a contact is still tracked. Default 0.1.

keepDistance: number = 0.05

Minimum separation kept from surfaces, in metres. Default 0.05.

maxAcceleration: number = 50

Maximum world-space acceleration used by calculateMovement. Default 50.

maxCastIterations: number = 10

Maximum number of cast iterations per integration step. Default 10.

maxCharacterSpeedForSolver: number = 10.0

Upper bound on per-solve character speed. Default 10.

maxSlopeCosine: number = 0.5

Cosine of the steepest slope the character can stand on. Default 0.5 (60°).

onTriggerCollisionObservable: CharacterCollisionObservable = ...

Fires once per dynamic body the character pushes during a step, just before the reactive impulse is applied. Mirrors Babylon.js' onTriggerCollisionObservable. Subscribe with .add(cb); the returned disposer removes the subscription.

penetrationRecoverySpeed: number = 1.0

Speed at which penetrations are pushed out. Default 1.0.

staticFriction: number = 0

Static-friction coefficient against surfaces. Default 0.

up: Vec3 = ...

World up vector. Default (0, 1, 0).

  • Compute a target velocity from the current state, a desired velocity, and surface info — a helper for steering input into surface-aware motion.

    Parameters

    • deltaTime: number

      Step duration in seconds.

    • forwardWorld: Vec3

      Character forward direction (world space).

    • surfaceNormal: Vec3

      Supporting surface normal.

    • currentVelocity: Vec3

      Current character velocity.

    • surfaceVelocity: Vec3

      Velocity induced by the surface.

    • desiredVelocity: Vec3

      Desired character velocity.

    • upWorld: Vec3

      Up vector (world space).

    Returns Vec3

    The new velocity vector.

  • Advance the controller using a velocity already chosen for this step (instead of a raw displacement). Mirrors Babylon.js' integrate: it picks a cast direction from the current velocity and surface info, then runs the collide-and-slide.

    Parameters

    • deltaTime: number

      Step duration in seconds.

    • surfaceInfo: CharacterSurfaceInfo

      Surface info from a prior checkSupport call.

    • gravity: Vec3

      Gravity applied to the character this step.

    Returns void

  • Set new shape options and rebuild the collision capsule accordingly.

    This is the supported way to change the capsule for common character features such as crouching, standing, crawling or sliding without recreating the controller (which would lose its position, velocity, support state and event subscriptions). The old Havok shape is released and replaced with a new one built from options.capsuleHeight / options.capsuleRadius.

    Parameters

    • options: PhysicsCharacterControllerOptions

      New capsule dimensions.

    • preserveFootPosition: boolean = true

      When true (default), the controller position is adapted so the world-space foot position (center - up * height/2) is kept fixed as the height changes; when false, the position is left unchanged.

    Returns void