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”.
- PhysXComponent
- .PhysXComponent.TypeName: string
- .allowQuery
- .allowSimulation
- .angularDamping
- .angularLockAxis
- .angularVelocity
- .blocksMask
- .bounciness
- .dynamicFriction
- .extents
- .gravity
- .groupsMask
- .kinematic
- .linearDamping
- .linearLockAxis
- .linearVelocity
- .mass
- .massSpaceInteriaTensor
- .rotationOffset
- .shape
- .shapeData
- .simulate
- .sleepOnActivate
- .static
- .staticFriction
- .translationOffset
- .trigger
- .addForce(f, m, localForce, p, local) ⇒ void
- .addTorque(f, m) ⇒ void
- .getAngularVelocity<T>(out) ⇒ T
- .getExtents<T>(out) ⇒ T
- .getLinearVelocity<T>(out) ⇒ T
- .getRotationOffset<T>(out) ⇒ T
- .getTranslationOffset<T>(out) ⇒ T
- .onCollision(callback) ⇒ number
- .onCollisionWith(otherComp, callback) ⇒ number
- .removeCollisionCallback(callbackId) ⇒ void
.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:
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
Equivalent to getAngularVelocity.
Note: Prefer to use getAngularVelocity for performance.
.angularVelocity
Set angular 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.9.0+Get bounciness.
.bounciness
0.9.0+Set bounciness.
.dynamicFriction: number
Get dynamicFriction.
.dynamicFriction
Set dynamicFriction
.extents: Float32Array
Equivalent to getExtents.
Note: Prefer to use getExtents for performance.
.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.
.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.
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
Equivalent to getLinearVelocity.
Note: Prefer to use getLinearVelocity for performance.
.linearVelocity
Set linear 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
1.1.1+Equivalent to getRotationOffset.
Gives a quick view of the offset in a debugger.
Note: Prefer to use getRotationOffset for performance.
.rotationOffset
1.1.1+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.10+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.10+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
1.1.5+true
if the rigid body is set to sleep upon activation, false
otherwise.
.sleepOnActivate
1.1.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
1.1.1+Equivalent to getTranslationOffset.
Gives a quick view of the offset in a debugger.
Note: Prefer to use getTranslationOffset for performance.
.translationOffset
1.1.1+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.
Param | Type | Description |
---|---|---|
f | Readonly<NumberArray> | Force vector. |
m | ForceMode | Force mode, see ForceMode, default Force . |
localForce | boolean | Whether the force vector is in local space, default false . |
p | Readonly<NumberArray> | Position to apply force at, default is center of mass. |
local | boolean | Whether 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.
Param | Type | Description |
---|---|---|
f | Readonly<NumberArray> | Force vector. |
m | ForceMode | Force mode, see ForceMode, default Force . |
.getAngularVelocity<T>(out: T) ⇒ T
.getAngularVelocity() ⇒ Float32Array
Angular velocity or [0, 0, 0]
if the component is not active.
Returns: The out
parameter.
Param | Type | Description |
---|---|---|
out | T | Destination array/vector, expected to have at least 3 elements. |
Template Param | Type Definition |
---|---|
T | extends NumberArray |
.getExtents<T>(out: T) ⇒ T
.getExtents() ⇒ Float32Array
The shape extents for collision detection.
Returns: The out
parameter.
Param | Type | Description |
---|---|---|
out | T | Destination array/vector, expected to have at least 3 elements. |
Template Param | Type Definition |
---|---|
T | extends NumberArray |
.getLinearVelocity<T>(out: T) ⇒ T
.getLinearVelocity() ⇒ Float32Array
Linear velocity or [0, 0, 0]
if the component is not active.
Returns: The out
parameter.
Param | Type | Description |
---|---|---|
out | T | Destination array/vector, expected to have at least 3 elements. |
Template Param | Type Definition |
---|---|
T | extends NumberArray |
.getRotationOffset<T>(out: T) ⇒ T
.getRotationOffset() ⇒ Float32Array
1.1.1+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.
Param | Type | Description |
---|---|---|
out | T | Destination array/vector, expected to have at least 4 elements. |
Template Param | Type Definition |
---|---|
T | extends NumberArray |
.getTranslationOffset<T>(out: T) ⇒ T
.getTranslationOffset() ⇒ Float32Array
1.1.1+Local translation offset.
Allows to move a physx component without creating a new object in the hierarchy.
Returns: The out
parameter.
Param | Type | Description |
---|---|---|
out | T | Destination array/vector, expected to have at least 3 elements. |
Template Param | Type Definition |
---|---|
T | extends NumberArray |
.onCollision(callback: CollisionCallback) ⇒ number
Add on collision callback.
Returns: Id of the new callback for use with removeCollisionCallback.
Param | Type | Description |
---|---|---|
callback | CollisionCallback | Function 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.
Param | Type | Description |
---|---|---|
otherComp | PhysXComponent | Component for which callbacks will be triggered. If you pass this component, the method is equivalent to. onCollision. |
callback | CollisionCallback | Function 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.
Param | Type | Description |
---|---|---|
callbackId | number | Callback id as returned by onCollision or onCollisionWith. |