interface IPhysicsEngine {
    debugRenderColliders: boolean;
    debugRenderRaycasts: boolean;
    enabled: boolean;
    get gravity(): Vec3;
    set gravity(vec3: Vec3): void;
    get isInitialized(): boolean;
    get isUpdating(): boolean;
    get world(): undefined | World;
    addBoxCollider(collider: ICollider, size: Vector3): any;
    addCapsuleCollider(
        collider: ICollider,
        radius: number,
        height: number,
    ): any;
    addFixedJoint(body1: IRigidbody, body2: IRigidbody): any;
    addForce(rb: IRigidbody, vec: Vec3, wakeup: boolean): any;
    addHingeJoint(
        body1: IRigidbody,
        body2: IRigidbody,
        anchor: Vec3,
        axis: Vec3,
    ): any;
    addMeshCollider(
        collider: ICollider,
        mesh: Mesh,
        convex: boolean,
        scale?: Vector3,
    ): any;
    addSphereCollider(collider: ICollider): any;
    applyImpulse(rb: IRigidbody, vec: Vec3, wakeup: boolean): any;
    clearCaches(): any;
    getAngularVelocity(rb: IRigidbody): null | Vec3;
    getBody(obj: ICollider | IRigidbody): any;
    getBody(obj: ICollider | IRigidbody): any;
    getComponent(rapierObject: object): null | IComponent;
    getLinearVelocity(rb: ICollider | IRigidbody): null | Vec3;
    initialize(): Promise<boolean>;
    isSleeping(rb: IRigidbody): undefined | boolean;
    postStep(): any;
    raycast(
        origin?: Vec3 | Vec2,
        direction?: Vec3,
        options?: {
            filterGroups?: number;
            filterPredicate?: (collider: ICollider) => boolean;
            maxDistance?: number;
            queryFilterFlags?: QueryFilterFlags;
            solid?: boolean;
        },
    ): RaycastResult;
    raycastAndGetNormal(
        origin?: Vec3 | Vec2,
        direction?: Vec3,
        options?: {
            filterGroups?: number;
            filterPredicate?: (collider: ICollider) => boolean;
            maxDistance?: number;
            queryFilterFlags?: QueryFilterFlags;
            solid?: boolean;
        },
    ): RaycastResult;
    removeBody(body: IComponent): any;
    resetForces(rb: IRigidbody, wakeup: boolean): any;
    resetTorques(rb: IRigidbody, wakeup: boolean): any;
    setAngularVelocity(rb: IRigidbody, vec: Vec3, wakeup: boolean): any;
    setLinearVelocity(rb: IRigidbody, vec: Vec3, wakeup: boolean): any;
    sphereOverlap(point: Vector3, radius: number): SphereOverlapResult[];
    step(dt: number): void;
    updateBody(
        comp: ICollider | IRigidbody,
        translation: boolean,
        rotation: boolean,
    ): any;
    updatePhysicsMaterial(collider: ICollider): any;
    updateProperties(rb: ICollider | IRigidbody): any;
    wakeup(rb: IRigidbody): any;
}

Implemented by

Properties

debugRenderColliders: boolean

Enable to render collider shapes

debugRenderRaycasts: boolean

Enable to visualize raycasts in the scene with gizmos

enabled: boolean

Enables or disables the physics engine

Accessors

  • get gravity(): Vec3

    Gets the current gravity vector

    Returns Vec3

  • set gravity(vec3: Vec3): void

    Sets the gravity vector for the physics simulation

    Parameters

    • vec3: 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

    Returns the underlying physics world object

    Returns undefined | World

Methods

  • Adds a box collider to the physics world

    Parameters

    • collider: ICollider

      The collider component to add

    • size: Vector3

      The size of the box

    Returns any

  • Adds a capsule collider to the physics world

    Parameters

    • collider: ICollider

      The collider component to add

    • radius: number

      The radius of the capsule

    • height: number

      The height of the capsule

    Returns any

  • Adds a continuous force to a rigidbody

    Parameters

    • rb: IRigidbody

      The rigidbody to add force to

    • vec: Vec3

      The force vector to add

    • wakeup: boolean

      Whether to wake up the rigidbody

    Returns any

  • 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

    • Optionalscale: Vector3

      Optional scale to apply to the mesh

    Returns any

  • Adds a sphere collider to the physics world

    Parameters

    • collider: ICollider

      The collider component to add

    Returns any

  • 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 any

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

    Returns any

  • 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

  • Gets the rapier physics body for a Needle component

    Parameters

    Returns any

    The underlying physics body or null if not found

  • Gets the physics body for a component

    Parameters

    Returns any

    The underlying physics body or null if not found

  • Gets the Needle Engine component for a rapier physics object

    Parameters

    • rapierObject: object

      The rapier physics object

    Returns null | IComponent

    The associated component or null if not found

  • Gets the linear velocity of a rigidbody or the rigidbody attached to a collider

    Parameters

    Returns null | Vec3

    The linear velocity vector or null if not available

  • Initializes the physics engine

    Returns Promise<boolean>

  • Checks if a rigidbody is currently sleeping

    Parameters

    Returns undefined | boolean

    Whether the rigidbody is sleeping or undefined if cannot be determined

  • Returns any

  • 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?: (collider: ICollider) => boolean;
          maxDistance?: number;
          queryFilterFlags?: QueryFilterFlags;
          solid?: boolean;
      }

      Additional raycast configuration options

      • OptionalfilterGroups?: number

        Raycast filter groups. Groups are used to apply the collision group rules for the scene query. The scene query will only consider hits with colliders with collision groups compatible with this collision group (using the bitwise test described in the collision groups section). For example membership 0x0001 and filter 0x0002 should be 0x00010002

      • OptionalfilterPredicate?: (collider: ICollider) => boolean

        Predicate to filter colliders in raycast results

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

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

    Returns RaycastResult

    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?: (collider: ICollider) => boolean;
          maxDistance?: number;
          queryFilterFlags?: QueryFilterFlags;
          solid?: boolean;
      }

      Additional raycast configuration options

      • OptionalfilterGroups?: number

        Raycast filter groups. Groups are used to apply the collision group rules for the scene query. The scene query will only consider hits with colliders with collision groups compatible with this collision group (using the bitwise test described in the collision groups section). For example membership 0x0001 and filter 0x0002 should be 0x00010002

      • OptionalfilterPredicate?: (collider: ICollider) => boolean

        Predicate to filter colliders in raycast results

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

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

    Returns RaycastResult

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

  • Removes a physics body from the simulation

    Parameters

    • body: IComponent

      The component whose physics body should be removed

    Returns any

  • 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 any

  • 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 any

  • 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 any

  • 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 any

  • Finds all colliders within a sphere

    Parameters

    • point: Vector3

      The center point of the sphere

    • radius: number

      The radius of the sphere

    Returns SphereOverlapResult[]

    Array of objects that overlap with the sphere

  • Advances physics simulation by the given time step

    Parameters

    • dt: 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 any

  • Updates the physics material properties of a collider

    Parameters

    Returns any

  • Updates the physical properties of a rigidbody or collider

    Parameters

    Returns any

  • Wakes up a sleeping rigidbody

    Parameters

    Returns any

MMNEPVFCICPMFPCPTTAAATR