Options
All
  • Public
  • Public/Protected
  • All
V1.7
  • V1.6
  • V1.7
Menu

Class PhysicsRigidBody

Defines the mass and movement properties of a physics object. A rigid body has no inherent shape, one or more PhysicsShapes need to be added to it.

A rigid body is one of 3 types: static, kinematic, or dynamic static : The body never moves. kinematic : The body can be moved by external systems, such as animation, but is not affected by forces or collisions. dynamic : The body is affected by forces and collisions.

It is important that apart from their initial position, static and dynamic bodies should not have their positions changed by calls to setLocalPosition, etc. This will cause unexpected results in the simulation.

Hierarchy

  • PhysicsRigidBody

Index

Constructors

constructor

Methods

addShape

  • addShape(shape: PhysicsShape | null, position?: [number, number, number] | Float32Array, rotation?: [number, number, number, number] | Float32Array): bigint
  • Adds a shape to the body. A shape may not be added to the body after it has been added to a Prism.

    priv

    none

    Parameters

    • shape: PhysicsShape | null

      The shape to add.

    • Optional position: [number, number, number] | Float32Array

      default = VEC3_ZERO
      Offset from the body's location to place the shape.

    • Optional rotation: [number, number, number, number] | Float32Array

      default = QUAT_IDENTITY
      Rotation of the shape relative to the body's orientation.

    Returns bigint

    Id of the shape for the body. INVALID_PHYSICS_ID if the shape was not added.

applyForce

  • applyForce(type: ForceType, force: [number, number, number] | Float32Array): void
  • Applies a force to the body. The force will only be applied for the current frame; to apply a continuous force, this function must be called every frame.

    priv

    none

    Parameters

    • type: ForceType

      Type of force to apply (force or impulse).

    • force: [number, number, number] | Float32Array

      Amount of force. Units depend on the force type.

    Returns void

applyForceAtPos

  • applyForceAtPos(type: ForceType, force: [number, number, number] | Float32Array, pos: [number, number, number] | Float32Array): void
  • Applies a force to the body at a given position. If the force is not at the center of mass, this will result in a torque being applied to the body as well. Both the force and position are in volume-space reference frame. The force will only be applied for the current frame; to apply a continuous force, this function must be called every frame.

    priv

    none

    Parameters

    • type: ForceType

      Type of force to apply (force or impulse).

    • force: [number, number, number] | Float32Array

      Amount of force. Units depend on the force type.

    • pos: [number, number, number] | Float32Array

      Position to apply the force

    Returns void

applyLocalForceAtPos

  • applyLocalForceAtPos(type: ForceType, force: [number, number, number] | Float32Array, pos: [number, number, number] | Float32Array): void
  • Applies a force to the body at a given position. If the force is not at the center of mass, this will result in a torque being applied to the body as well. Both the force and position are in local-space of the body reference frame. The force will only be applied for the current frame; to apply a continuous force, this function must be called every frame.

    priv

    none

    Parameters

    • type: ForceType

      Type of force to apply (force or impulse).

    • force: [number, number, number] | Float32Array

      Amount of force. Units depend on the force type.

    • pos: [number, number, number] | Float32Array

      Position to apply the force

    Returns void

applyTorque

  • applyTorque(type: ForceType, force: [number, number, number] | Float32Array): void
  • Applies a torque to the body. The torque will only be applied for the current frame; to apply a continuous torque, this function must be called every frame.

    priv

    none

    Parameters

    • type: ForceType

      Type of torque to apply (force or impulse).

    • force: [number, number, number] | Float32Array

      Amount of torque. Units depend on the force type.

    Returns void

clearColliderFlag

  • clearColliderFlag(flag: number): void

clearCollidesWithFlag

  • clearCollidesWithFlag(flag: number): void

clearForce

  • clearForce(): void

clearTorque

  • clearTorque(): void

getAngularDamping

  • getAngularDamping(): number

getAngularVelocity

  • getAngularVelocity(): [number, number, number]

getBodyType

getCenterOfMass

  • getCenterOfMass(): [number, number, number]

getColliderFlags

  • getColliderFlags(): number

getCollidesWithFlags

  • getCollidesWithFlags(): number

getInertiaTensor

  • getInertiaTensor(): [number, number, number]

getLinearDamping

  • getLinearDamping(): number

getLinearVelocity

  • getLinearVelocity(): [number, number, number]

getMass

  • getMass(): number

getMaxAngularVelocity

  • getMaxAngularVelocity(): number

getSleepThreshold

  • getSleepThreshold(): number

isColliderFlagSet

  • isColliderFlagSet(flag: number): boolean
  • Returns if a given collider flag is set.

    priv

    none

    Parameters

    • flag: number

      Flag value, in the range of 0 - 31.

    Returns boolean

    true if the flag is set.

isCollidesWithFlagSet

  • isCollidesWithFlagSet(flag: number): boolean
  • Returns if a given collides with flag is set.

    priv

    none

    Parameters

    • flag: number

      Flag value, in the range of 0 - 31.

    Returns boolean

    true if the flag is set.

lockAxes

node

  • node(): Node | null

removeShape

  • removeShape(id: bigint): boolean
  • Removes a shape from the body. A shape may not be removed from the body after it has been added to a Prism.

    priv

    none

    Parameters

    • id: bigint

      Id of the shape to remove.

    Returns boolean

    true if the shape was removed

setAngularDamping

  • setAngularDamping(damping: number): void
  • Sets angular damping coefficient being applied to the body. This can be used to simulate things like rolling friction.

    priv

    none

    Parameters

    • damping: number

      Damping coefficient

    Returns void

setAngularVelocity

  • setAngularVelocity(velocity: [number, number, number] | Float32Array): void

setBodyType

  • Sets the rigid body type (static/kinematic/dynamic). Changing this may result in the loss of data for the body in the simulation. The preferred way to change the body type is to remove the body from its volume, change the type, and re-add to the volume.

    priv

    none

    Parameters

    Returns void

    The body type.

setCenterOfMass

  • setCenterOfMass(com: [number, number, number] | Float32Array): void
  • Sets the center of mass of the body. Note setting it outside the body's area as defined by the shapes attached to it may result in an unstable simulation.

    priv

    none

    Parameters

    • com: [number, number, number] | Float32Array

      Center of mass

    Returns void

setColliderFlag

  • setColliderFlag(flag: number): void

setColliderFlags

  • setColliderFlags(flags: number): void
  • Sets the collider flags for the body. If the collider flags of one body anded with the collides with flags of another body is 0, the bodies will not collide.

    priv

    none

    Parameters

    • flags: number

      Collider flags.

    Returns void

setCollidesWithFlag

  • setCollidesWithFlag(flag: number): void

setCollidesWithFlags

  • setCollidesWithFlags(flags: number): void
  • Sets the collides with flags for the body. If the collider flags of one body anded with the collides with flags of another body is 0, the bodies will not collide.

    priv

    none

    Parameters

    • flags: number

      Collides with flags.

    Returns void

setEnableCCD

  • setEnableCCD(enable: boolean): void
  • Enable/disable continuous collision detection (CCD) for this body. Enabling CCD can be used to prevent a body from "tunneling" through another due to it moving too fast.

    IMPORTANT: Physics must have been enabled with the solverType initialization data set to kFastNormal or kFastFast for this to have an effect.

    priv

    none

    Parameters

    • enable: boolean

      Flag to enable CCD on the body.

    Returns void

setIgnoreGravity

  • setIgnoreGravity(ignore: boolean): void

setInertiaTensor

  • setInertiaTensor(tensor: [number, number, number] | Float32Array): void
  • Sets the inertia tensor of the body. A value of 0 is the equivalent of infinite inertia on the axis.

    priv

    none

    Parameters

    • tensor: [number, number, number] | Float32Array

      Inertia tensor.

    Returns void

setLinearDamping

  • setLinearDamping(damping: number): void
  • Sets linear damping coefficient being applied to the body. This can be used to simulate things like air resistance.

    priv

    none

    Parameters

    • damping: number

      Damping coefficient

    Returns void

setLinearVelocity

  • setLinearVelocity(velocity: [number, number, number] | Float32Array): void

setMass

  • setMass(massKg: number): void

setMaxAngularVelocity

  • setMaxAngularVelocity(velocity: number): void
  • Sets the maximum angular velocity of the body. This helps keep the simulation stable; it can become unstable if the object rotates too fast.

    priv

    none

    Parameters

    • velocity: number

      Max velocity

    Returns void

setSleepThreshold

  • setSleepThreshold(threshold: number): void
  • Sets the sleep threshold of the body. This controls when the body is marked to be stopped simulating due to lack of motion.

    priv

    none

    Parameters

    • threshold: number

      Sleep threshold value

    Returns void

Generated using TypeDoc