Implements

Constructors

Properties

debugRenderColliders: boolean = false

Enable to render collider shapes

debugRenderRaycasts: boolean = false

Enable to visualize raycasts in the scene with gizmos

enabled: boolean = false

Enables or disables the physics engine

Accessors

  • get gravity(): Vec3

    Sets the gravity vector for the physics simulation

    Returns Vec3

  • set gravity(value: Vec3): void

    Sets the gravity vector for the physics simulation

    Parameters

    • value: Vec3

    Returns void

  • get isInitialized(): boolean

    Indicates whether the physics engine has been initialized

    Returns boolean

  • get isUpdating(): boolean

    Indicates whether the physics engine is currently updating

    Returns boolean

  • get world(): undefined | World

    Get access to the rapier world

    Returns undefined | World

Methods

  • Adds a capsule collider to the physics world

    Parameters

    • collider: ICollider

      The collider component to add

    • height: number

      The height of the capsule

    • radius: number

      The radius of the capsule

    Returns Promise<void>

  • Adds a continuous force to a rigidbody

    Parameters

    • rigidbody: IRigidbody
    • force: Vec3
    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns void

  • The joint prevents any relative movement between two rigid-bodies, except for relative rotations along one axis. This is typically used to simulate wheels, fans, etc. They are characterized by one local anchor as well as one local axis on each rigid-body.

    Parameters

    • body1: IRigidbody
    • body2: IRigidbody
    • anchor: { x: number; y: number; z: number }
    • axis: { x: number; y: number; z: number }

    Returns void

  • Parameters

    Returns void

  • Adds a mesh collider to the physics world

    Parameters

    • collider: ICollider

      The collider component to add

    • mesh: Mesh

      The mesh to use for collision

    • convex: boolean

      Whether the collision mesh should be treated as convex

    • OptionalextraScale: Vector3

    Returns Promise<void>

  • Applies an instantaneous impulse to a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to apply impulse to

    • vec: Vec3

      The impulse vector to apply

    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns void

  • Clears all cached data (e.g., mesh data when creating scaled mesh colliders)

    Returns void

  • Gets the angular velocity of a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to get angular velocity from

    Returns null | Vec3

    The angular velocity vector or null if not available

  • Checks if a rigidbody is currently sleeping

    Parameters

    Returns undefined | boolean

    Whether the rigidbody is sleeping or undefined if cannot be determined

  • Performs a fast raycast against physics colliders

    Parameters

    • Optionalorigin: Vec3 | Vec2

      Ray origin in screen or worldspace

    • Optionaldirection: Vec3

      Ray direction in worldspace

    • Optionaloptions: {
          filterGroups?: number;
          filterPredicate?: (c: ICollider) => boolean;
          maxDistance?: number;
          queryFilterFlags?: QueryFilterFlags;
          solid?: boolean;
          useIgnoreRaycastLayer?: boolean;
      }

      Additional raycast configuration options

      • OptionalfilterGroups?: number
      • OptionalfilterPredicate?: (c: ICollider) => boolean

        Return false to ignore this collider

      • OptionalmaxDistance?: number
      • OptionalqueryFilterFlags?: QueryFilterFlags
      • Optionalsolid?: boolean

        True if you want to also hit objects when the raycast starts from inside a collider

      • OptionaluseIgnoreRaycastLayer?: boolean

        When enabled the hit object's layer will be tested. If layer 2 is enabled the object will be ignored (Layer 2 == IgnoreRaycast) If not set the raycast will ignore objects in the IgnoreRaycast layer (default: true)

        undefined
        

    Returns null | { collider: ICollider; point: Vector3 }

    Raycast result containing hit point and collider, or null if no hit

  • Performs a raycast that also returns the normal vector at the hit point

    Parameters

    • Optionalorigin: Vec3 | Vec2

      Ray origin in screen or worldspace

    • Optionaldirection: Vec3

      Ray direction in worldspace

    • Optionaloptions: {
          filterGroups?: number;
          filterPredicate?: (c: ICollider) => boolean;
          maxDistance?: number;
          queryFilterFlags?: QueryFilterFlags;
          solid?: boolean;
          useIgnoreRaycastLayer?: boolean;
      }

      Additional raycast configuration options

      • OptionalfilterGroups?: number
      • OptionalfilterPredicate?: (c: ICollider) => boolean

        Return false to ignore this collider

      • OptionalmaxDistance?: number
      • OptionalqueryFilterFlags?: QueryFilterFlags
      • Optionalsolid?: boolean

        True if you want to also hit objects when the raycast starts from inside a collider

      • OptionaluseIgnoreRaycastLayer?: boolean

        When enabled the hit object's layer will be tested. If layer 2 is enabled the object will be ignored (Layer 2 == IgnoreRaycast) If not set the raycast will ignore objects in the IgnoreRaycast layer (default: true)

        undefined
        

    Returns null | { collider: ICollider; normal: Vector3; point: Vector3 }

    Raycast result containing hit point, normal, and collider, or null if no hit

  • Resets all forces acting on a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to reset forces on

    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns void

  • Resets all torques acting on a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to reset torques on

    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns void

  • Sets the angular velocity of a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to set angular velocity for

    • vec: Vec3

      The angular velocity vector to set

    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns void

  • Sets the linear velocity of a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to set linear velocity for

    • vec: Vec3

      The linear velocity vector to set

    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns void

  • Precice sphere overlap detection using rapier against colliders

    Parameters

    • point: Vector3

      center of the sphere in worldspace

    • radius: number

      radius of the sphere

    Returns SphereOverlapResult[]

    array of colliders that overlap with the sphere. Note: they currently only contain the collider and the gameobject

  • Advances physics simulation by the given time step

    Parameters

    • Optionaldt: number

    Returns void

  • Updates the position and/or rotation of a physics body

    Parameters

    • comp: ICollider | IRigidbody

      The collider or rigidbody component to update

    • translation: boolean

      Whether to update the position

    • rotation: boolean

      Whether to update the rotation

    Returns void