Skip to content

Class: Rigidbody

Rigidbody Component Rigid bodies can endow game objects with physical properties, allowing them to be controlled by the physics system and subjected to forces and torques, thus achieving realistic motion effects.

Hierarchy

  • ComponentBase

    Rigidbody

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Rigidbody(): Rigidbody

Returns

Rigidbody

Inherited from

ComponentBase.constructor

Properties

collisionShape

Static Readonly collisionShape: typeof CollisionShapeUtil = CollisionShapeUtil

Defined in

packages/physics/rigidbody/Rigidbody.ts:40


group

group: number

The collision group of the rigid body.

Defined in

packages/physics/rigidbody/Rigidbody.ts:233


mask

mask: number

The collision mask of the rigid body.

Defined in

packages/physics/rigidbody/Rigidbody.ts:238


object3D

object3D: Object3D = null

owner object3D

Inherited from

ComponentBase.object3D

Defined in

src/components/ComponentBase.ts:17


isDestroyed

Optional isDestroyed: boolean

Inherited from

ComponentBase.isDestroyed

Defined in

src/components/ComponentBase.ts:38

Accessors

btBodyInited

get btBodyInited(): boolean

Check if rigidbody inited

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:193


btRigidbody

get btRigidbody(): btRigidBody

Return internal Ammo.btRigidBody

Returns

btRigidBody

Defined in

packages/physics/rigidbody/Rigidbody.ts:200


shape

get shape(): btCollisionShape

The collision shape of the rigid body.

Returns

btCollisionShape

Defined in

packages/physics/rigidbody/Rigidbody.ts:214

set shape(value): void

Parameters

NameType
valuebtCollisionShape

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:217


userIndex

get userIndex(): number

User index, which can be used as an identifier for the rigid body.

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:243

set userIndex(value): void

Sets the user index for the rigid body.

Parameters

NameType
valuenumber

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:250


activationState

get activationState(): ActivationState

Activation state of the rigid body.

Returns

ActivationState

Defined in

packages/physics/rigidbody/Rigidbody.ts:258

set activationState(value): void

Sets the activation state of the rigid body.

Parameters

NameType
valueActivationState

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:265


collisionFlags

get collisionFlags(): number

Collision flags of the rigid body.

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:273


isKinematic

get isKinematic(): boolean

Check if the rigidbody affect physics system

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:295

set isKinematic(value): void

Set the rigid body to a kinematic object

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:301


isTrigger

get isTrigger(): boolean

Check if the rigid body is a trigger

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:327

set isTrigger(value): void

Set the rigid body as a trigger

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:333


isDisableDebugVisible

get isDisableDebugVisible(): boolean

Check if the rigid body is visible in debug mode

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:340

set isDisableDebugVisible(value): void

Set the rigid body to be visible in debug mode

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:346


margin

get margin(): number

Margin of the collision shape.

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:353

set margin(value): void

Sets the margin of the collision shape.

Parameters

NameType
valuenumber

Returns

void

Default

ts
0.02

Defined in

packages/physics/rigidbody/Rigidbody.ts:360


damping

get damping(): [number, number]

Damping of the rigid body.

Sets the damping parameters. The first value is the linear damping, the second is the angular damping.

Returns

[number, number]

Defined in

packages/physics/rigidbody/Rigidbody.ts:371

set damping(params): void

Parameters

NameType
params[number, number]

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:375


contactProcessingThreshold

get contactProcessingThreshold(): number

Contact processing threshold of the rigid body.

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:382

set contactProcessingThreshold(value): void

Sets the contact processing threshold of the rigid body.

Parameters

NameType
valuenumber

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:388


gravity

get gravity(): Vector3

Gravity vector applied to the rigid body.

Returns

Vector3

Defined in

packages/physics/rigidbody/Rigidbody.ts:395

set gravity(value): void

Sets the gravity vector applied to the rigid body.

Parameters

NameType
valueVector3

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:401


friction

get friction(): number

Get friction value

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:408

set friction(value): void

Set friction value. default 0.5

Parameters

NameType
valuenumber

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:414


rollingFriction

get rollingFriction(): number

Get rolling friction value

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:421

set rollingFriction(value): void

Set rolling friction value

Parameters

NameType
valuenumber

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:427


restitution

get restitution(): number

Get restitution value

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:434

set restitution(value): void

Set restitution value default 0.5

Parameters

NameType
valuenumber

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:440


velocity

get velocity(): Vector3

Get velocity value of current object

Returns

Vector3

Defined in

packages/physics/rigidbody/Rigidbody.ts:447

set velocity(value): void

Set velocity value of current object

Parameters

NameType
valueVector3

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:453


angularVelocity

get angularVelocity(): Vector3

Get the angular velocity value of current object

Returns

Vector3

Defined in

packages/physics/rigidbody/Rigidbody.ts:461

set angularVelocity(value): void

Set the angular velocity value of current object

Parameters

NameType
valueVector3

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:470


linearVelocity

get linearVelocity(): Vector3

Get the linear velocity value of current object

Returns

Vector3

Defined in

packages/physics/rigidbody/Rigidbody.ts:477

set linearVelocity(value): void

Set the linear velocity value of current object

Parameters

NameType
valueVector3

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:486


mass

get mass(): number

Get mass value

Returns

number

Defined in

packages/physics/rigidbody/Rigidbody.ts:493

set mass(value): void

Set mass value. default 0.01

Parameters

NameType
valuenumber

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:499


isSilent

get isSilent(): boolean

刚体的静默状态。 如果为 true 则任何物理对象与静默状态的对象发生碰撞时都不会触发双方的碰撞回调。

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:526

set isSilent(value): void

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:529


ccdSettings

get ccdSettings(): [number, number]

Returns

[number, number]

Defined in

packages/physics/rigidbody/Rigidbody.ts:550

set ccdSettings(params): void

CCD (Continuous Collision Detection)

Sets the CCD parameters. The first value is the motion threshold, the second is the swept sphere radius.

Parameters

NameTypeDescription
params[number, number][motion threshold, swept sphere radius]

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:544


enableCollisionEvent

get enableCollisionEvent(): boolean

Enable/disable collision callbacks

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:557

set enableCollisionEvent(value): void

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:560


collisionEvent

get collisionEvent(): (contactPoint: btManifoldPoint, selfBody: btRigidBody, otherBody: btRigidBody) => void

Collision callbacks

Returns

fn

▸ (contactPoint, selfBody, otherBody): void

Parameters
NameType
contactPointbtManifoldPoint
selfBodybtRigidBody
otherBodybtRigidBody
Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:568

set collisionEvent(callback): void

Parameters

NameType
callback(contactPoint: btManifoldPoint, selfBody: btRigidBody, otherBody: btRigidBody) => void

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:571


enablePhysicsTransformSync

get enablePhysicsTransformSync(): boolean

Enables or disables the transform sync with physics. If enabled, changes to the transform will automatically update the physics body.

Returns

boolean

Defined in

packages/physics/rigidbody/Rigidbody.ts:579

set enablePhysicsTransformSync(value): void

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:582


eventDispatcher

get eventDispatcher(): CEventDispatcher

Returns

CEventDispatcher

Inherited from

ComponentBase.eventDispatcher

Defined in

src/components/ComponentBase.ts:23

set eventDispatcher(value): void

Parameters

NameType
valueCEventDispatcher

Returns

void

Inherited from

ComponentBase.eventDispatcher

Defined in

src/components/ComponentBase.ts:28


isStart

get isStart(): boolean

Returns

boolean

Inherited from

ComponentBase.isStart

Defined in

src/components/ComponentBase.ts:40


transform

get transform(): Transform

Return the Transform component attached to the Object3D.

Returns

Transform

Inherited from

ComponentBase.transform

Defined in

src/components/ComponentBase.ts:47


enable

get enable(): boolean

Enable/disable components. The enabled components can be updated, while the disabled components cannot be updated.

Returns

boolean

Inherited from

ComponentBase.enable

Defined in

src/components/ComponentBase.ts:68

set enable(value): void

Enable/disable components. The enabled components can be updated, while the disabled components cannot be updated.

Parameters

NameType
valueboolean

Returns

void

Inherited from

ComponentBase.enable

Defined in

src/components/ComponentBase.ts:54

Methods

init

init(): void

Returns

void

Overrides

ComponentBase.init

Defined in

packages/physics/rigidbody/Rigidbody.ts:42


start

start(): void

Returns

void

Overrides

ComponentBase.start

Defined in

packages/physics/rigidbody/Rigidbody.ts:47


onUpdate

onUpdate(): void

Returns

void

Overrides

ComponentBase.onUpdate

Defined in

packages/physics/rigidbody/Rigidbody.ts:123


updateTransform

updateTransform(position?, rotation?, clearFV?): void

更新刚体的位置和旋转,并同步三维对象

Parameters

NameTypeDescription
position?Vector3可选,默认为三维对象的位置
rotation?Vector3 | Quaternion可选,默认为三维对象的欧拉角旋转
clearFV?boolean可选,清除刚体的力和速度,默认为 false

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:173


clearForcesAndVelocities

clearForcesAndVelocities(): void

Remove the force and velocity of the rigid body

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:184


wait

wait(): Promise<btRigidBody>

Asynchronously retrieves the fully initialized rigid body instance.

Returns

Promise<btRigidBody>

Defined in

packages/physics/rigidbody/Rigidbody.ts:206


addCollisionFlag

addCollisionFlag(value): void

Adds a collision flag to the rigid body.

Parameters

NameType
valueCollisionFlags

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:280


removeCollisionFlag

removeCollisionFlag(value): void

Removes a collision flag from the rigid body.

Parameters

NameType
valueCollisionFlags

Returns

void

Defined in

packages/physics/rigidbody/Rigidbody.ts:287


destroy

destroy(force?): void

Parameters

NameType
force?boolean

Returns

void

Overrides

ComponentBase.destroy

Defined in

packages/physics/rigidbody/Rigidbody.ts:587


stop

stop(): void

Returns

void

Inherited from

ComponentBase.stop

Defined in

src/components/ComponentBase.ts:114


onEnable

onEnable(view?): any

Parameters

NameType
view?View3D

Returns

any

Inherited from

ComponentBase.onEnable

Defined in

src/components/ComponentBase.ts:115


onDisable

onDisable(view?): any

Parameters

NameType
view?View3D

Returns

any

Inherited from

ComponentBase.onDisable

Defined in

src/components/ComponentBase.ts:116


onLateUpdate

onLateUpdate(view?): any

Parameters

NameType
view?View3D

Returns

any

Inherited from

ComponentBase.onLateUpdate

Defined in

src/components/ComponentBase.ts:118


onBeforeUpdate

onBeforeUpdate(view?): any

Parameters

NameType
view?View3D

Returns

any

Inherited from

ComponentBase.onBeforeUpdate

Defined in

src/components/ComponentBase.ts:119


onCompute

onCompute(view?, command?): any

Parameters

NameType
view?View3D
command?GPUCommandEncoder

Returns

any

Inherited from

ComponentBase.onCompute

Defined in

src/components/ComponentBase.ts:120


onGraphic

onGraphic(view?): any

Parameters

NameType
view?View3D

Returns

any

Inherited from

ComponentBase.onGraphic

Defined in

src/components/ComponentBase.ts:121


onParentChange

onParentChange(lastParent?, currentParent?): any

Parameters

NameType
lastParent?Object3D
currentParent?Object3D

Returns

any

Inherited from

ComponentBase.onParentChange

Defined in

src/components/ComponentBase.ts:122


onAddChild

onAddChild(child): any

Parameters

NameType
childObject3D

Returns

any

Inherited from

ComponentBase.onAddChild

Defined in

src/components/ComponentBase.ts:123


onRemoveChild

onRemoveChild(child): any

Parameters

NameType
childObject3D

Returns

any

Inherited from

ComponentBase.onRemoveChild

Defined in

src/components/ComponentBase.ts:124


cloneTo

cloneTo(obj): void

clone component data to target object3D

Parameters

NameTypeDescription
objObject3Dtarget object3D

Returns

void

Inherited from

ComponentBase.cloneTo

Defined in

src/components/ComponentBase.ts:131


copyComponent

copyComponent(from): this

Parameters

NameType
fromthis

Returns

this

Inherited from

ComponentBase.copyComponent

Defined in

src/components/ComponentBase.ts:133


beforeDestroy

beforeDestroy(force?): void

before release this component, object refrences are not be set null now.

Parameters

NameType
force?boolean

Returns

void

Inherited from

ComponentBase.beforeDestroy

Defined in

src/components/ComponentBase.ts:200

Released under the MIT License