RSX Code Reference
    Preparing search index...

    Class Rigidbody

    Rigidbody is a dynamic physics object that can be moved using forces (or directly). It will interact with other static and dynamic physics objects in the scene accordingly (it will push other non-kinematic rigidbodies, and collide with static objects).

    The shape and mass of a rigidbody is governed by its colliders. You must attach at least one collider for the rigidbody to be valid.


    @inspectableField([Array, Number])
    public objectCounts: number[] = [1, 2, 3];

    @inspectableField(Number)
    @description("Sets the default size of all the interactive gizmos used to modify a scene object's transform.")
    @defaultValue(1)
    @slider(0.01, 2)
    public objectSize: number = 1;

    Hierarchy (View Summary)

    Index
    • get active(): boolean

      Activates or deactivates the component.

      Returns boolean

      The returned active state also accounts for the active state of the parent SceneObject.

    • set active(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get angularDrag(): number

      Determines the angular drag of the body. Higher drag values means the object resists angular movement more.

      Returns number

    • set angularDrag(value: number): void

      Parameters

      • value: number

      Returns void

    • get centerOfMass(): Immutable<Vector3>

      Determines the rigidbody's center of mass. This will be calculated automatically if the RigidbodyFlag::AutoCenterOfMass flag is set.

      Returns Immutable<Vector3>

      Changing this property will unset the RigidbodyFlag::AutoCenterOfMass flag and override the automatically calculated value. To revert back to automatic center of mass calculation, set the RigidbodyFlag::AutoCenterOfMass again using rigidbodyFlags.

    • set centerOfMass(value: Immutable<Vector3>): void

      Parameters

      Returns void

    • get drag(): number

      Determines the linear drag of the body. Higher drag values means the object resists linear movement more.

      Returns number

    • set drag(value: number): void

      Parameters

      • value: number

      Returns void

    • get editorMetaData(): Settings

      Get the editor meta data.

      Returns Settings

      The API is only valid in the editor.

    • get inertiaTensorDiagonal(): Immutable<Vector3>

      Determines the rigidbody's inertia tensor, together with inertiaTensorRotation. The inertia tensor determines how much the rigidbody will resist angular forces, similar to how the mass determines how much the rigidbody resists linear forces. The rotational part of the tensor determines the three main rotation axes of the body. The diagonal part determines how much the body resists angular forces around each of these axes. This will be calculated automatically if the RigidbodyFlag::AutoInertiaTensor flag is set.

      Returns Immutable<Vector3>

      Changing this property will unset the RigidbodyFlag::AutoInertiaTensor flag and override the automatically calculated value. To revert back to automatic inertai tensor calculation, set the RigidbodyFlag::AutoInertiaTensor again using rigidbodyFlags.

    • set inertiaTensorDiagonal(value: Immutable<Vector3>): void

      Parameters

      Returns void

    • get inertiaTensorRotation(): Immutable<Quaternion>

      Determines the rigidbody's inertia tensor, together with inertiaTensorRotation. The inertia tensor determines how much the rigidbody will resist angular forces, similar to how the mass determines how much the rigidbody resists linear forces. The rotational part of the tensor determines the three main rotation axes of the body. The diagonal part determines how much the body resists angular forces around each of these axes. This will be calculated automatically if the RigidbodyFlag::AutoInertiaTensor flag is set.

      Returns Immutable<Quaternion>

      Changing this property will unset the RigidbodyFlag::AutoInertiaTensor flag and override the automatically calculated value. To revert back to automatic inertai tensor calculation, set the RigidbodyFlag::AutoInertiaTensor again using rigidbodyFlags.

    • set inertiaTensorRotation(value: Immutable<Quaternion>): void

      Parameters

      Returns void

    • get isActiveSelf(): boolean

      Determines whether the component itself is active, without accounting for the active state of the parent scene object.

      Returns boolean

    • get isDestroyed(): boolean

      Determines if the object has been destroyed.

      Returns boolean

    • get isKinematic(): boolean

      Determines if the body is kinematic. Kinematic body will not move in response to external forces (for example gravity, or another object pushing it), essentially behaving like collider. Unlike a collider though, you can still move the object and have other dynamic objects respond correctly (meaning it will push other objects).

      Returns boolean

    • set isKinematic(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get isRunning(): boolean

      Determines if the component is currently active, enabled and running.

      Returns boolean

    • get isSleeping(): boolean

      Checks if the body is sleeping. Objects that aren't moved/rotated for a while are put to sleep to reduce load on the physics system.

      Returns boolean

    • get mass(): number

      Determines the mass of the entire rigidbody. If the RigidbodyFlag::AutoMass flag is set, then this is the sum of the masses of all attached collider shapes.

      Returns number

      Changing this property will unset the RigidbodyFlag::AutoMass and override the collider masses. To go back to automatic mass calculation, set the RigidbodyFlag::AutoMass flag again using rigidbodyFlags.

    • set mass(value: number): void

      Parameters

      • value: number

      Returns void

    • get maximumAngularVelocity(): number

      Determines the maximum angular velocity of the rigidbody. Velocity will be clamped to this value.

      Returns number

    • set maximumAngularVelocity(value: number): void

      Parameters

      • value: number

      Returns void

    • get positionSolverCount(): number

      Determines the number of iterations to use when solving for position. Higher values can improve precision and numerical stability of the simulation.

      Returns number

    • set positionSolverCount(value: number): void

      Parameters

      • value: number

      Returns void

    • get priority(): number

      The signed execution priority of the component.

      Determines order of execution of this component in relation to other components, higher priorities will execute earlier. The priority value determines the order of initialize, enable and update calls. Valid priorities are in the range [-100...100], other priorities are reserved for internal use.

      The priority should not be modified after onCreate has been called.

      The default priority for user implement components is -10. BuiltinComponent have a default priority of 0. However, instances that have dependencies or are a dependency to another component might have non zero default priorities. For example, the Camera component has a default priority of 50 as other components may depend on the camera being initialized early. The Rigidbody component has a default priority of 22 and Joint components have a priority of 20 as the joint depends on fully initialized rigid bodies.

      Returns number

      If two components have the same priority, the order of execution is undefined, but deterministic as the system uses identifiers such as the internal type ID and UUID to guaranteed stable ordering.

    • set priority(value: number): void

      Parameters

      • value: number

      Returns void

    • get useGravity(): boolean

      Determines whether or not the rigidbody will have the global gravity force applied to it.

      Returns boolean

    • set useGravity(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get uuid(): UUID

      Returns a universally unique identifier that persists scene save/load.

      Returns UUID

    • get velocitySolverCount(): number

      Determines the number of iterations to use when solving for velocity. Higher values can improve precision and numerical stability of the simulation.

      Returns number

    • set velocitySolverCount(value: number): void

      Parameters

      • value: number

      Returns void

    • Virtual

      Calculates bounds of the visible content for this component.

      Returns { box: AABox; sphere: Sphere }

      An object with the bounding box and bounding sphere or null, if the component has no bounds.

    • Destroys the component, removing it from its scene object and stopping component updates.

      Parameters

      • Optionalimmediate: boolean

        If true the component will be fully destroyed immediately. This means that objects that are still referencing this component might fail. Normally destruction is delayed until the end of the frame to give other objects a chance to stop using it.

      Returns void

    • Virtual

      Returns the bounds of the visible content for this component in local space, i.e. relative to the scene object's transform.

      Returns { box: AABox; sphere: Sphere }

      An object with the bounding box and bounding sphere or null, if the component has no bounds.

    • Calls a parameterless method with the specified name, on the component.

      Parameters

      • name: string

        Name of the method to call.

      Returns boolean

      true if the method was invoked.

    • Moves the rigidbody to a specific position. This method will ensure physically correct movement, meaning the body will collide with other objects along the way.

      Parameters

      Returns void

    • Virtual

      Called once when the component has been created.

      Returns void

      Called regardless of the state the component is in.

    • Virtual

      Called once just before the component is destroyed.

      Returns void

      Called regardless of the state the component is in.

    • Virtual

      Called every time a component is placed into the Stopped state.

      Returns void

      This method may be called during component destruction, if the component wasn't already in ScenePlayState.Stopped state during destruction. When called during destruction, it is called before onDestroy.

    • Virtual

      Called every time a component leaves the ScenePlayState.Stopped state.

      Returns void

      This method might be called during component creation, if the requirements for leaving the stopped state are met. One such case would be a component class that has the runInEditor attribute. When called during creation it is called after onInitialize.

    • Called at fixed time intervals (e.g. 60 times per frame). Only called if the component is in ScenePlayState.Playing state.

      Returns void

      RSX uses the fixed update to perform updates to sub-systems such as physics. Only implement this method if your logic depends on fixed updates (e.g. at 30hz) for stability.

    • Virtual

      Called once when the component first leaves the ScenePlayState.Stopped state.

      Returns void

      This method might be called during component creation, if the requirements for leaving the stopped state are met. One such case would be a component class that has the runInEditor attribute. When called during creation it is called after onCreate.

    • Virtual

      Called once per frame, after all other components received their onUpdate invocation. Only called if the component is in ScenePlayState.Playing state.

      Returns void

      This method should only be implemented if your component needs logic that implements on other component or SceneObject changes performend in onUpdate. An example could be a camera controller logic that updates in response to changes to the object that is being tracked.

    • Virtual

      Called when the script domain has been refreshed or when the component is initialized. During initialization it is called after onInitialize but before onEnable.

      Returns void

      This API will not be called in a deployment build.

    • Virtual

      Called once per frame. Only called if the component is in ScenePlayState.Playing state.

      Returns void

    • Rotates the rigidbody. This method will ensure physically correct rotation, meaning the body will collide with other objects along the way.

      Parameters

      Returns void

    • Forces the object to sleep. Useful if you know the object will not move in any significant way for a while.

      Returns void

    • Registers the coroutine for the specified component using the provided args as arguments.

      Type Parameters

      Parameters

      • coroutine: T

        The coroutine.

      • ...args: Parameters<T>

      Returns boolean

      true if the coroutine was registered.

      The coroutine will be called for the first time when the coroutine subsystem runs for update events. There is no guarantee with regards to the order of how coroutines are invoked. Coroutines are a great way for time-deferred or delayed system. To implement a coroutine simply add a generator method to your component and register it as coroutine:

      		public *myCoroutine(text:string)
      {
      const endTime:number = Time.realElapsed + 3;

      while(Time.realElapsed < endTime)
      {
      yield true;
      }

      Debug.log("This code will be invoked after 3 seconds with the text=" + text);
      }

      To register the function simply call

      		this.startCoroutine(this.myCoroutine, "Hello World!");
      

      The function will be invoked once the coroutine runs. The coroutine function can yield the program control flow by using the keyword yield. The coroutine will then stop execution at that point, and pick up the execution in the next update event, right after the yield keyword that caused the coroutine to pause.

      With helper functions such as waitForSeconds or waitForAsyncOp it is easy to create coroutines that pause for a set time interval.

    • Registers the coroutine for the specified component using the provided args as arguments.

      Type Parameters

      Parameters

      • coroutine: T

        The coroutine.

      • ...args: Parameters<T>

      Returns boolean

      true if the coroutine was registered.

      The coroutine will be called for the first time when the coroutine subsystem runs for fixedUpdate events. There is no guarantee with regards to the order of how coroutines are invoked. Coroutines are a great way for time-deferred or delayed system. To implement a coroutine simply add a generator method to your component and register it as coroutine:

      		public *myCoroutine(text:string)
      {
      const endTime:number = Time.realElapsed + 3;

      while(Time.realElapsed < endTime)
      {
      yield true;
      }

      Debug.log("This code will be invoked after 3 seconds!");
      }

      To register the function simply call

      		this.startCoroutine(this.myCoroutine, "Hello World!");
      

      The function will be invoked once the coroutine runs. The coroutine function can yield the program control flow by using the keyword yield. The coroutine will then stop execution at that point, and pick up the execution in the next fixedUpdate event, right after the yield keyword that caused the coroutine to pause.

      With helper functions such as waitForSeconds or waitForAsyncOp it is easy to create coroutines that pause for a set time interval.

    • Stops all coroutines for the specified component.

      Returns void

      This API is only available for components that are registered in a scene.

    • Returns a string representation of an object.

      Returns string

    • Wakes an object up. Useful if you modified properties of this object, and potentially surrounding objects which might result in the object being moved by physics (although the physics system will automatically wake the object up for majority of such cases).

      Returns void

    • Locates a rsx object by its sceneRuntimeID and UUID.

      Parameters

      • sceneRuntimeID: number

        The runtime ID of the SceneInstance of the object.

      • uuid: Const<UUID>

        The UUID of the object to retrieve.

      Returns SceneNode

      The object or null if no object with given sceneRuntimeID and uuid has been registered

    onCollisionBegin: Event<[data: CollisionData]>

    Triggered when one of the colliders owned by the rigidbody starts colliding with another object.

    onCollisionStay: Event<[data: CollisionData]>

    Triggered when a previously colliding collider stays in collision. Triggered once per frame.

    onCollisionEnd: Event<[data: CollisionData]>

    Triggered when one of the colliders owned by the rigidbody stops colliding with another object.