A Rigidbody is used together with a Collider to create physical interactions between objects in the scene.

Hierarchy (View Summary, Expand)

Implements

Properties

angularDrag: number = 1

Angular drag is a force that resists the rotation of the rigid-body. It is applied to the center-of-mass of the rigid-body.

autoMass: boolean = true

When true the mass will be automatically calculated by the attached colliders

centerOfMass: Vector3 = ...

The center of mass is the point around which the mass of the rigid-body is evenly distributed. It is used to compute the torque applied to the rigid-body when forces are applied to it.

collisionDetectionMode: CollisionDetectionMode = CollisionDetectionMode.Discrete
constraints: RigidbodyConstraints = RigidbodyConstraints.None

Constraints are used to lock the position or rotation of an object in a specific axis.

detectCollisions: boolean = true

Detect collisions is a flag that can be set to false to disable collision detection for a specific rigid-body.

dominanceGroup: number = 0

Rigidbodies with higher dominance will be immune to forces originating from contacts with rigidbodies of lower dominance.

drag: number = 0

Drag is a force that resists the motion of the rigid-body. It is applied to the center-of-mass of the rigid-body.

gameObject: GameObject

Reference to the GameObject this component is attached to This is a three.js Object3D with additional GameObject functionality

guid: string = "invalid"

Unique identifier for this component instance, used for finding and tracking components

isKinematic: boolean = false

IsKinematic is a flag that can be set to true to make a rigid-body kinematic. Kinematic rigid-bodies are not affected by forces and collisions. They are meant to be animated by the user.

sleepThreshold: number = 0.01

The sleeping threshold is the minimum velocity below which a dynamic rigid-body will be put to sleep by the physics engine.

sourceId?: string

Identifier for the source asset that created this component. For example, URL to the glTF file this component was loaded from

useGravity: boolean = true

Use gravity is a flag that can be set to false to disable gravity for a specific rigid-body.

Accessors

  • get activeAndEnabled(): boolean

    Checks if this component is currently active (enabled and part of an active GameObject hierarchy) Components that are inactive won't receive lifecycle method calls

    Returns boolean

    True if the component is enabled and all parent GameObjects are active

  • get context(): Context

    The context this component belongs to, providing access to the runtime environment including physics, timing utilities, camera, and scene

    Returns Context

  • set context(context: Context): void

    Parameters

    Returns void

  • get destroyed(): boolean

    Checks if this component has been destroyed

    Returns boolean

    True if the component or its GameObject has been destroyed

  • get enabled(): boolean

    Controls whether this component is enabled Disabled components don't receive lifecycle callbacks

    Returns boolean

  • set enabled(val: boolean): void

    Parameters

    • val: boolean

    Returns void

  • get forward(): Vector3

    Gets the forward direction vector (0,0,-1) of this component's GameObject in world space

    Returns Vector3

  • get gravityScale(): number

    Returns number

  • set gravityScale(val: number): void

    Gravity is such a common force that it is implemented as a special case (even if it could easily be implemented by the user using force application). Note however that a change of gravity won't automatically wake-up the sleeping bodies so keep in mind that you may want to wake them up manually before a gravity change.

    It is possible to change the way gravity affects a specific rigid-body by setting the rigid-body's gravity scale to a value other than 1.0. The magnitude of the gravity applied to this body will be multiplied by this scaling factor. Therefore, a gravity scale set to 0.0 will disable gravity for the rigid-body whereas a gravity scale set to 2.0 will make it twice as strong. A negative value will flip the direction of the gravity for this rigid-body.

    Parameters

    • val: number

    Returns void

  • get isRigidbody(): boolean

    Returns boolean

  • get isSleeping(): undefined | boolean

    Returns undefined | boolean

  • get layer(): number

    The layer value of the GameObject this component is attached to Used for visibility and physics filtering

    Returns number

  • get mass(): number

    Returns number

  • set mass(value: number): void

    By default the mass will be automatically calculated (see autoMass) by the physics engine using the collider sizes
    To set the mass manually you can either set the mass value or set autoMass to false

    Parameters

    • value: number

    Returns void

  • get name(): string

    The name of the GameObject this component is attached to Used for debugging and finding objects

    Returns string

  • set name(str: string): void

    Parameters

    • str: string

    Returns void

  • get right(): Vector3

    Gets the right direction vector (1,0,0) of this component's GameObject in world space

    Returns Vector3

  • get scene(): Scene

    Shorthand accessor for the current scene from the context

    Returns Scene

    The scene this component belongs to

  • get smoothedVelocity(): Vector3

    Returns the rigidbody velocity smoothed over ~ 10 frames

    Returns Vector3

  • get static(): boolean

    Indicates whether the GameObject is marked as static Static objects typically don't move and can be optimized by the engine

    Returns boolean

  • set static(value: boolean): void

    Parameters

    • value: boolean

    Returns void

  • get tag(): string

    The tag of the GameObject this component is attached to Used for categorizing objects and efficient lookup

    Returns string

  • set tag(str: string): void

    Parameters

    • str: string

    Returns void

  • get up(): Vector3

    Gets the up direction vector (0,1,0) of this component's GameObject in world space

    Returns Vector3

  • get worldEuler(): Euler

    Gets the rotation of this component's GameObject in world space as Euler angles (in radians)

    Returns Euler

  • set worldEuler(val: Euler): void

    Sets the rotation of this component's GameObject in world space using Euler angles (in radians)

    Parameters

    • val: Euler

      The world rotation Euler angles to set

    Returns void

  • get worldPosition(): Vector3

    Gets the position of this component's GameObject in world space

    Returns Vector3

  • set worldPosition(val: Vector3): void

    Sets the position of this component's GameObject in world space

    Parameters

    • val: Vector3

      The world position vector to set

    Returns void

  • get worldQuaternion(): Quaternion

    Gets the rotation of this component's GameObject in world space as a quaternion

    Returns Quaternion

  • set worldQuaternion(val: Quaternion): void

    Sets the rotation of this component's GameObject in world space using a quaternion

    Parameters

    • val: Quaternion

      The world rotation quaternion to set

    Returns void

  • get worldRotation(): Vector3

    Gets the rotation of this component's GameObject in world space as Euler angles (in degrees)

    Returns Vector3

  • set worldRotation(val: Vector3): void

    Sets the rotation of this component's GameObject in world space using Euler angles (in degrees)

    Parameters

    • val: Vector3

      The world rotation vector to set (in degrees)

    Returns void

Methods

  • Registers an event listener for the specified event type

    Type Parameters

    Parameters

    • type: string

      The event type to listen for

    • listener: (evt: T) => any

      The callback function to execute when the event occurs

    Returns void

  • Called once when the component becomes active for the first time. This is the first lifecycle callback to be invoked

    Returns void

  • Returns Generator<undefined, void, unknown>

  • Destroys this component and removes it from its GameObject After destruction, the component will no longer receive lifecycle callbacks

    Returns void

  • Dispatches an event to all registered listeners

    Parameters

    • evt: Event

      The event object to dispatch

    Returns boolean

    Always returns false (standard implementation of EventTarget)

  • Called at the beginning of each frame before regular updates. Use for logic that needs to run before standard update callbacks.

    Returns void

  • Called after all update functions have been called. Use for calculations that depend on other components being updated first.

    Returns void

  • Called after the scene has been rendered. Use for post-processing or UI updates that should happen after rendering

    Returns void

  • Called immediately before the scene is rendered.

    Parameters

    • frame: null | XRFrame

      Current XRFrame if in an XR session, null otherwise

    Returns void

  • Called before an XR session is requested Use to modify session initialization parameters

    Parameters

    • mode: XRSessionMode

      The XR session mode being requested

    • args: XRSessionInit

      The session initialization parameters that can be modified

    Returns void

  • Called when the component is destroyed. Use for cleanup operations like removing event listeners

    Returns void

  • Called every time the component becomes disabled or inactive in the hierarchy. Invoked when the component or any parent GameObject becomes invisible

    Returns void

  • Called when the context's pause state changes.

    Parameters

    • isPaused: boolean

      Whether the context is currently paused

    • wasPaused: boolean

      The previous pause state

    Returns void

  • Removes a previously registered event listener

    Type Parameters

    Parameters

    • type: string

      The event type the listener was registered for

    • listener: (arg: T) => any

      The callback function to remove

    Returns void

  • Parameters

    • wakeup: boolean = true

    Returns void

  • Returns void

  • Parameters

    • wakeup: boolean = true

    Returns void

  • Returns void

  • Called when this component needs to remap guids after an instantiate operation.

    Parameters

    • guidsMap: GuidsMap

      Mapping from old guids to newly generated guids

    Returns void

  • Parameters

    • x: Vec3
    • Optionalwakeup: boolean

    Returns any

  • Parameters

    • x: number
    • y: number
    • z: number
    • Optionalwakeup: boolean

    Returns any

  • d

    Parameters

    • _velocity: null | Vector3 | { x: number; y: number; z: number } = null

    Returns void

    not used anymore and will be removed in a future update

  • Set the angular velocity of a rigidbody (equivalent to calling setAngularVelocity)

    Parameters

    • x: Vec3

    Returns any

  • Set the angular velocity of a rigidbody (equivalent to calling setAngularVelocity)

    Parameters

    • x: number
    • y: number
    • z: number

    Returns any

  • Parameters

    • x: number | Vector3
    • Optionaly: number
    • Optionalz: number
    • wakeup: boolean = true

    Returns void

  • Sets the position of this component's GameObject in world space using individual coordinates

    Parameters

    • x: number

      X-coordinate in world space

    • y: number

      Y-coordinate in world space

    • z: number

      Z-coordinate in world space

    Returns void

  • Sets the rotation of this component's GameObject in world space using quaternion components

    Parameters

    • x: number

      X component of the quaternion

    • y: number

      Y component of the quaternion

    • z: number

      Z component of the quaternion

    • w: number

      W component of the quaternion

    Returns void

  • Sets the rotation of this component's GameObject in world space using individual Euler angles

    Parameters

    • x: number

      X-axis rotation

    • y: number

      Y-axis rotation

    • z: number

      Z-axis rotation

    • degrees: boolean = true

      Whether the values are in degrees (true) or radians (false)

    Returns void

  • Called once at the beginning of the first frame after the component is enabled. Use for initialization that requires other components to be awake.

    Returns void

  • Starts a coroutine that can yield to wait for events. Coroutines allow for time-based sequencing of operations without blocking. Coroutines are based on generator functions, a JavaScript language feature.

    Parameters

    • routine: Generator

      Generator function to start

    • evt: FrameEvent = FrameEvent.Update

      Event to register the coroutine for (default: FrameEvent.Update)

    Returns Generator

    The generator function that can be used to stop the coroutine

    Time-based sequencing of operations

    *myCoroutine() {
    yield WaitForSeconds(1); // wait for 1 second
    yield WaitForFrames(10); // wait for 10 frames
    yield new Promise(resolve => setTimeout(resolve, 1000)); // wait for a promise to resolve
    }

    Coroutine that logs a message every 5 frames

    onEnable() {
    this.startCoroutine(this.myCoroutine());
    }
    private *myCoroutine() {
    while(this.activeAndEnabled) {
    console.log("Hello World", this.context.time.frame);
    // wait for 5 frames
    for(let i = 0; i < 5; i++) yield;
    }
    }
  • Stops a coroutine that was previously started with startCoroutine

    Parameters

    • routine: Generator

      The routine to be stopped

    • evt: FrameEvent = FrameEvent.Update

      The frame event the routine was registered with

    Returns void

  • Determines if this component supports a specific XR mode

    Parameters

    • mode: XRSessionMode

      The XR session mode to check support for

    Returns boolean

    True if the component supports the specified mode

  • Teleport the rigidbody to a new position in the world.
    Will reset forces before setting the object world position

    Parameters

    • pt: { x: number; y: number; z: number }

      The new position to teleport the object to (world space)

    • localspace: boolean = true

      When true the object will be teleported in local space, otherwise in world space

    Returns void

  • Called once per frame during the main update loop. The primary location for frame-based game logic.

    Returns void

  • Call to force an update of the rigidbody properties in the physics engine

    Returns any

  • When a dynamic rigid-body doesn't move (or moves very slowly) during a few seconds, it will be marked as sleeping by the physics pipeline. Rigid-bodies marked as sleeping are no longer simulated by the physics engine until they are woken up. That way the physics engine doesn't waste any computational resources simulating objects that don't actually move. They are woken up automatically whenever another non-sleeping rigid-body starts interacting with them (either with a joint, or with one of its attached colliders generating contacts).

    Returns void

MMNEPVFCICPMFPCPTTAAATR