PhysXComponent

Native physx rigid body component.

Provides access to a native mesh component instance. Only available when using physx enabled runtime, see “Project Settings > Runtime”.

.TypeName: string 

.allowQuery: boolean 

Whether this rigid body may be queried in ray casts.

.allowQuery 

Set whether this rigid body may be queried in ray casts.

.allowSimulation: boolean 

Whether to allow simulation of this rigid body.

.allowSimulation 

Set whether to allow simulation of this rigid body.

allowSimulation and trigger can not be enabled at the same time. Enabling allowSimulation while trigger is enabled will disable trigger.

.angularDamping: number 

Get angularDamping.

.angularDamping 

Set angularDamping.

.angularLockAxis: LockAxis 

Get the angular lock axes flags.

To get the state of a specific flag, Bitwise AND with the LockAxis needed:

1if(body.angularLockAxis & LockAxis.Y) {
2    console.log("The Y flag was set!");
3}

Returns: axes that are currently locked for angular movement.

.angularLockAxis 

Set axes to lock for angular velocity.

Note: This has no effect if the component is static.

.angularVelocity: Float32Array 

Angular velocity or [0, 0, 0] if the component is not active.

.angularVelocity 

Set angular velocity

PhysX Manual - “Velocity”

Has no effect, if the component is not active.

.blocksMask: number 

Get the components blocks mask flags.

Each bit represents membership to the block, see example.

 1// Block overlap with any objects in group 2
 2c.blocksMask = (1 << 2);
 3
 4// Block overlap with any objects in group 0
 5c.blocksMask  = (1 << 0)
 6
 7// Block overlap with any objects in group 0 and 2
 8c.blocksMask = (1 << 0) | (1 << 2);
 9
10(c.blocksMask & (1 << 2)) != 0; // true
11(c.blocksMask & (1 << 7)) != 0; // false

.blocksMask 

Set the components blocks mask.

.bounciness: number 

0.8.5+

Get bounciness.

.bounciness 

0.8.5+

Set bounciness.

.dynamicFriction: number 

Get dynamicFriction.

.dynamicFriction 

Set dynamicFriction

.extents: Float32Array 

The shape extents for collision detection.

.extents 

0.8.5+

Set the shape extents for collision detection.

.gravity: boolean 

Whether this rigid body’s gravity flag is enabled.

.gravity 

Set whether this rigid body’s gravity is enabled.

.groupsMask: number 

Get the components groups mask flags.

Each bit represents membership to group, see example.

 1// Assign c to group 2
 2c.groupsMask = (1 << 2);
 3
 4// Assign c to group 0
 5c.groupsMask  = (1 << 0);
 6
 7// Assign c to group 0 and 2
 8c.groupsMask = (1 << 0) | (1 << 2);
 9
10(c.groupsMask & (1 << 2)) != 0; // true
11(c.groupsMask & (1 << 7)) != 0; // false

.groupsMask 

Set the components groups mask.

.kinematic: boolean 

Whether this rigid body is kinematic.

.kinematic 

Set whether this rigid body is kinematic.

.linearDamping: number 

Get linearDamping/

.linearDamping 

Set linearDamping.

.linearLockAxis: LockAxis 

Get the linear lock axes flags.

To get the state of a specific flag, Bitwise AND with the LockAxis needed.

1if(body.linearLockAxis & LockAxis.Y) {
2    console.log("The Y flag was set!");
3}

Returns: axes that are currently locked for linear movement.

.linearLockAxis 

Set axes to lock for linear velocity.

Note: This has no effect if the component is static.

.linearVelocity: Float32Array 

Linear velocity or [0, 0, 0] if the component is not active.

.linearVelocity 

Set linear velocity.

PhysX Manual - “Velocity”

Has no effect, if the component is not active.

.mass: number 

Mass

.mass 

Set mass.

PhysX Manual - “Mass Properties”

.massSpaceInteriaTensor 

Set mass space interia tensor.

PhysX Manual - “Mass Properties”

Has no effect, if the component is not active.

.rotationOffset: Float32Array 

0.8.5+

Equivalent to getRotationOffset.

Gives a quick view of the offset in a debugger.

Note: Prefer to use getRotationOffset for performance.

.rotationOffset 

0.8.5+

Set the offset rotation.

The array must be a quaternion of at least 4 elements.

Note: The component must be re-activated to apply the change.

.shape: Shape 

The shape for collision detection.

.shape 

0.8.5+

Set the shape for collision detection.

.shapeData: null | { index: number; } 

0.8.5+

Additional data for the shape.

null for Shape values: None, Sphere, Capsule, Box, Plane. {index: n} for TriangleMesh and ConvexHull.

This data is currently only for passing onto or creating other PhysXComponent.

.shapeData 

0.8.5+

Set additional data for the shape.

Retrieved only from shapeData.

.simulate: boolean 

Whether this rigid body’s simulate flag is enabled.

.simulate 

Set whether this rigid body’s simulate flag is enabled.

.sleepOnActivate: boolean 

0.8.5+

true if the rigid body is set to sleep upon activation, false otherwise.

.sleepOnActivate 

0.8.5+

Set the rigid body to sleep upon activation.

When asleep, the rigid body will not be simulated until the next contact.

.static: boolean 

Whether this rigid body is static.

This property returns whether the rigid body is effectively static. If static property was set while the rigid body was active, it will not take effect until the rigid body is set inactive and active again. Until the component is set inactive, this getter will return whether the rigid body is actually static.

.static 

Set whether this rigid body is static.

Setting this property only takes effect once the component switches from inactive to active.

.staticFriction: number 

Get staticFriction.

.staticFriction 

Set staticFriction.

.translationOffset: Float32Array 

0.8.5+

Equivalent to getTranslationOffset.

Gives a quick view of the offset in a debugger.

Note: Prefer to use getTranslationOffset for performance.

.translationOffset 

0.8.5+

Set the offset translation.

The array must be a vector of at least 3 elements.

Note: The component must be re-activated to apply the change.

.trigger: boolean 

Whether this physics body is a trigger.

.trigger 

Set whether this physics body is a trigger.

allowSimulation and trigger can not be enabled at the same time. Enabling trigger while allowSimulation is enabled, will disable allowSimulation.

.addForce(f: Readonly<NumberArray>, m: ForceMode, localForce: boolean, p: Readonly<NumberArray>, local: boolean) ⇒ void 

Apply a force.

PhysX Manual - “Applying Forces and Torques”

Has no effect, if the component is not active.

ParamTypeDescription
fReadonly<NumberArray>Force vector.
mForceModeForce mode, see ForceMode, default Force.
localForcebooleanWhether the force vector is in local space, default false.
pReadonly<NumberArray>Position to apply force at, default is center of mass.
localbooleanWhether position is in local space, default false.

.addTorque(f: Readonly<NumberArray>, m: ForceMode) ⇒ void 

Apply torque.

PhysX Manual - “Applying Forces and Torques”

Has no effect, if the component is not active.

ParamTypeDescription
fReadonly<NumberArray>Force vector.
mForceModeForce mode, see ForceMode, default Force.

.getRotationOffset<T>(out: T) ⇒ T 

.getRotationOffset() ⇒ Float32Array

0.8.5+

Local rotation offset represented as a quaternion.

Allows to rotate a physx component without creating a new object in the hierarchy.

Returns: The out parameter.

ParamTypeDescription
outTDestination array/vector, expected to have at least 4 elements.
Template ParamType Definition
Textends NumberArray

.getTranslationOffset<T>(out: T) ⇒ T 

.getTranslationOffset() ⇒ Float32Array

0.8.5+

Local translation offset.

Allows to move a physx component without creating a new object in the hierarchy.

Returns: The out parameter.

ParamTypeDescription
outTDestination array/vector, expected to have at least 3 elements.
Template ParamType Definition
Textends NumberArray

.onCollision(callback: CollisionCallback) ⇒ number 

Add on collision callback.

Returns: Id of the new callback for use with removeCollisionCallback.

ParamTypeDescription
callbackCollisionCallbackFunction to call when this rigid body (un)collides with any other. js let rigidBody = this.object.getComponent('physx'); rigidBody.onCollision(function(type, other) { // Ignore uncollides if(type == CollisionEventType.TouchLost) return; // Take damage on collision with enemies if(other.object.name.startsWith("enemy-")) { this.applyDamage(10); } }.bind(this));

.onCollisionWith(otherComp: PhysXComponent, callback: CollisionCallback) ⇒ number 

Add filtered on collision callback.

Returns: Id of the new callback for use with removeCollisionCallback.

ParamTypeDescription
otherCompPhysXComponentComponent for which callbacks will be triggered. If you pass this component, the method is equivalent to. onCollision.
callbackCollisionCallbackFunction to call when this rigid body (un)collides with otherComp.

.removeCollisionCallback(callbackId: number) ⇒ void 

Remove a collision callback added with onCollision or onCollisionWith.

Throws: When the callback does not belong to the component.

Throws: When the callback does not exist.

ParamTypeDescription
callbackIdnumberCallback id as returned by onCollision or onCollisionWith.