Skip to main content

Physics

API for physics-related functions.

Constants

Physics.IS_DEBUGGER_AVAILABLE

Whether the physics debugger is available. True on debug builds, false otherwise.

Physics.IS_DEBUGGER_AVAILABLE: boolean

Functions

Physics.removePhysics

Removes the static or dynamic rigid-body attached to an entity.

Physics.removePhysics(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to remove physics from.

Physics.addEventListener

Adds an event listener. A list of events can be found here.

Physics.addEventListener(eventType: string, callback: function): function

Parameters

NameTypeDefault ValueDescription
eventTypestringRequiredThe event to listen for.
callbackfunctionRequiredThe callback to use.

Returns

NameTypeDescription
callbackfunctionThe callback that was registered.

Physics.removeEventListener

Removes an event listener.

Physics.removeEventListener(eventType: string, callback: function)

Parameters

NameTypeDefault ValueDescription
eventTypestringRequiredThe event to remove the listener from.
callbackfunctionRequiredThe callback to remove.

Functions - Articulations

Physics.makeArticulationRoot

Adds a an articulation to an entity and makes it the root link. You can read more about articulations here: https://nvidia-omniverse.github.io/PhysX/physx/5.6.1/docs/Articulations.html.

Note that regardless of the disableSelfCollision setting (which affects all collision within the articulation), the parent and child of an articulation link will never collide with each other.

Physics.makeArticulationRoot(entity: entity, options?: table)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to make an articulation.
optionstable?"{ fixedBase = false, disableSelfCollision = false }"Optional configuration for the articulation. Set the whole table or individual properties to nil to use defaults.

Adds an articulation link rigid-body to an entity.

Physics.makeArticulationLink(entity: entity, parent: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to make an articulation link.
parententityRequiredThe parent entity. Must have an articulation link already.

Physics.isArticulationRoot

Checks whether the entity is the root of an articulation.

Physics.isArticulationRoot(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to check.

Returns

NameTypeDescription
isArticulationRootbooleanWhether the entity is an articulation root.

Checks whether the entity is a link of an articulation.

Physics.isArticulationLink(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to check.

Returns

NameTypeDescription
isArticulationLinkbooleanWhether the entity is an articulation link.

Physics.getArticulationRoot

Returns the root of the articulation which this entity is a part of. Throws if the entity is not part of an articulation.

Physics.getArticulationRoot(entity: entity): entity

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to get the articulation root of.

Returns

NameTypeDescription
articulationRootentityThe entity at the root of the articulation.

Physics.getArticulationParent

Returns the parent of an entity's articulation link. Throws if the entity is not part of an articulation.

Physics.getArticulationParent(entity: entity): entity?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to get the parent link of.

Returns

NameTypeDescription
parententity?Parent articulation link, or nil if this entity was the root link.

Physics.getArticulationChildren

Returns the child links of an entity's articulation link. Throws if the entity is not part of an articulation.

Physics.getArticulationChildren(entity: entity): entity[]

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to get the child links of.

Returns

NameTypeDescription
childrenentity[]Child articulation links.

Functions - Character Controllers

Physics.createController

Creates a new PhysX character controller with the given options. This is a very low level API which requires you to determine the displacement for the controller each frame (including applying gravity and tracking whether the controller is grounded).

In most cases you'll want to use one of the provided character controllers in the /character-controllers folder. If you do need to implement your own character controller from scratch, you should read through https://nvidia-omniverse.github.io/PhysX/physx/5.4.2/docs/CharacterControllers.html first.

Physics.createController(options: ControllerCreateOptions): BoxController | CapsuleController

Parameters

NameTypeDefault ValueDescription
optionsControllerCreateOptionsRequiredNo description

Returns

NameTypeDescription
controllerBoxController | CapsuleControllerBox or capsule controller depending on options.shape.

Physics.moveController

Apply a displacement vector to the given character controller, performing collision checks on surrounding geometry.

The displacement should be premultiplied by the time between this and the previous moveController call if the rate of movement should be framerate independent.

Physics.moveController(controller: BoxController | CapsuleController, displacement: vector, minDistance: number, deltaTime: number): ControllerMoveResult

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description
displacementvectorRequiredDisplacement relative to the controller's centre
minDistancenumberRequiredMinimum distance below which the displacement (after applying collision) will be considered as no movement.
deltaTimenumberRequiredTime (in seconds) between this and the previous moveController call.

Returns

NameTypeDescription
resultControllerMoveResultNo description

Physics.setControllerHeight

Sets the controller's height, not including the contact offset (aka skin) or the radius (for capsule controllers).

Physics.setControllerHeight(controller: BoxController | CapsuleController, height: number)

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description
heightnumberRequiredNo description

Physics.setControllerSideExtent

Sets the size of the box controller's collider on the left/right axis.

Physics.setControllerSideExtent(controller: BoxController, sideExtent: number)

Parameters

NameTypeDefault ValueDescription
controllerBoxControllerRequiredNo description
sideExtentnumberRequiredNo description

Physics.setControllerForwardExtent

Sets the size of the box controller's collider on the forward/backward axis.

Physics.setControllerForwardExtent(controller: BoxController, forwardExtent: number)

Parameters

NameTypeDefault ValueDescription
controllerBoxControllerRequiredNo description
forwardExtentnumberRequiredNo description

Physics.setControllerRadius

Sets the cylinder and end cap radius of the capsule controller's collider

Physics.setControllerRadius(controller: CapsuleController, radius: number)

Parameters

NameTypeDefault ValueDescription
controllerCapsuleControllerRequiredNo description
radiusnumberRequiredNo description

Physics.setControllerPosition

Sets the controller's position without performing any collision or overlap tests. You should ensure that the position has sufficient space for the controller's collider.

Physics.setControllerPosition(controller: BoxController | CapsuleController, position: vector)

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description
positionvectorRequiredNo description

Physics.setControllerFootPosition

Sets the controller's position without performing any collision or overlap tests. You should ensure that the position has sufficient space for the controller's collider.

Similar to Physics.setControllerPosition, except the vector positions the bottom extent of the collider (including contact offset) as opposed to the centre.

Physics.setControllerFootPosition(controller: BoxController | CapsuleController, position: vector)

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description
positionvectorRequiredNo description

Physics.setControllerUpDirection

Sets the up direction of the controller, adjusting the collider rotation and auto-stepping.

TODO: Check if this transforms the displacement vector passed to Physics.moveController and document either way.

Physics.setControllerUpDirection(controller: BoxController | CapsuleController, upDirection: vector)

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description
upDirectionvectorRequiredNo description

Physics.setControllerStepOffset

Sets the step offset of the controller.

Physics.setControllerStepOffset(controller: BoxController | CapsuleController, stepOffset: number)

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description
stepOffsetnumberRequiredNo description

Physics.getControllerPosition

Gets the position of the controller's centre.

Physics.getControllerPosition(controller: BoxController | CapsuleController): vector

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description

Returns

NameTypeDescription
positionvectorNo description

Physics.getControllerFootPosition

Gets the position of the bottom extent of the controller's collider (including contact offset).

Physics.getControllerFootPosition(controller: BoxController | CapsuleController): vector

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description

Returns

NameTypeDescription
footPositionvectorNo description

Physics.getControllerUpDirection

Gets the up direction of the controller.

Physics.getControllerUpDirection(controller: BoxController | CapsuleController): vector

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description

Returns

NameTypeDescription
upDirectionvectorNo description

Physics.getControllerStepOffset

Gets the step offset of the controller.

Physics.getControllerStepOffset(controller: BoxController | CapsuleController): number

Parameters

NameTypeDefault ValueDescription
controllerBoxController | CapsuleControllerRequiredNo description

Returns

NameTypeDescription
stepOffsetnumberNo description

Functions - Colliders

Physics.createCollider

Creates a new collider with geometry and mass properties.

Physics.createCollider(geometry: PhysicsGeometry): Collider

Parameters

NameTypeDefault ValueDescription
geometryPhysicsGeometryRequiredGeometry to use.

Returns

NameTypeDescription
colliderColliderThe created collider.

Physics.attachCollider

Attaches the collider to an entity's rigid-body. Colliders may only be attached to one rigid-body at a time.

Physics.attachCollider(entity: entity, collider: Collider)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to attach to.
colliderColliderRequiredCollider to attach.

Physics.detachCollider

Detaches the collider from its rigid-body. Throws if not attached to a rigid-body (check with getColliderEntity).

Physics.detachCollider(collider: Collider)

Parameters

NameTypeDefault ValueDescription
colliderColliderRequiredCollider to detach.

Physics.getColliders

Gets all colliders attached to the entity's rigid-body.

Physics.getColliders(entity: entity): Collider[]

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to get the colliders of.

Returns

NameTypeDescription
collidersCollider[]List of attached colliders.

Physics.getColliderEntity

Gets the entity this collider is attached to.

Physics.getColliderEntity(collider: Collider): entity?

Parameters

NameTypeDefault ValueDescription
colliderColliderRequiredCollider to get the entity of.

Returns

NameTypeDescription
entityentity?Entity this collider is attached to, or nil if not attached.

Functions - Damping

Physics.getLinearDamping

Gets the linear damping of a rigid body.

Physics.getLinearDamping(entity: entity): number

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
dampingnumberThe linear damping of the rigid body.

Physics.setLinearDamping

Sets the linear damping of a rigid body.

Physics.setLinearDamping(entity: entity, damping: number)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
dampingnumberRequiredThe linear damping to set.

Physics.getAngularDamping

Gets the angular damping of a rigid body.

Physics.getAngularDamping(entity: entity): number

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
dampingnumberThe angular damping of the rigid body.

Physics.setAngularDamping

Sets the angular damping of a rigid body.

Physics.setAngularDamping(entity: entity, damping: number)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
dampingnumberRequiredThe angular damping to set.

Functions - Debugging

Physics.connectDebugger

Connects the PhysX Visual Debugger. This function is only available on debug builds.

Physics.connectDebugger(host: string, port: number, timeout: number)

Parameters

NameTypeDefault ValueDescription
hoststringRequiredThe host to connect to.
portnumberRequiredThe port to connect to.
timeoutnumberRequiredThe timeout in milliseconds.

Physics.disconnectDebugger

Disconnects the PhysX Visual Debugger. This function is only available on debug builds.

Physics.disconnectDebugger()

Physics.isDebuggerConnected

Checks if the PhysX Visual Debugger is connected. This function is only available on debug builds.

Physics.isDebuggerConnected(): boolean

Returns

NameTypeDescription
connectedbooleanWhether the debugger is connected.

Functions - Force & Torque

Physics.addForce

Adds a force to a rigid body.

Force accumulation

Forces are accumulated until the next physics step. To clear the accumulated forces, call clearForce.

Physics.addForce(entity: entity, force: vector, mode?: ForceMode)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
forcevectorRequiredThe force to add.
modeForceMode?"ForceMode.Force"The force mode.

Physics.addTorque

Adds a torque to a rigid body.

Torque accumulation

Torques are accumulated until the next physics step. To clear the accumulated torques, call clearTorque.

Physics.addTorque(entity: entity, torque: vector, mode?: ForceMode)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
torquevectorRequiredThe torque to add.
modeForceMode?"ForceMode.Force"The force mode.

Physics.addForceAtPosition

Adds a force to a rigid-body at the given position in world space, affecting both its linear and angular velocity.

Force accumulation

Forces are accumulated until the next physics step. To clear the accumulated forces, call clearForce.

Physics.addForceAtPosition(entity: entity, force: number, globalPosition: vector, mode?: ForceMode)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to add the force to.
forcenumberRequiredForce to add.
globalPositionvectorRequiredGlobal position to add the force to.
modeForceMode?"ForceMode.Force"The force mode.

Physics.clearForce

Clears the currently accumulated forces of a rigid body.

Physics.clearForce(entity: entity, mode?: ForceMode)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
modeForceMode?"ForceMode.Force"The force mode of the forces to clear.

Physics.clearTorque

Clears the currently accumulated torques of a rigid body.

Physics.clearTorque(entity: entity, mode?: ForceMode)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
modeForceMode?"ForceMode.Force"The force mode of the torques to clear.

Functions - Geometry

Physics.createSphere

Creates a sphere geometry with the given radius.

Physics.createSphere(radius: number): PhysicsGeometry

Parameters

NameTypeDefault ValueDescription
radiusnumberRequiredNo description

Returns

NameTypeDescription
spherePhysicsGeometryNo description

Physics.createCapsule

Creates a capsule geometry with the given radius and half height. The total height can be calculated as 2 * (radius + halfHeight).

The capsule is oriented along the X-axis in the geometry's local coordinate space. To orient it vertically when creating a shape, set the shape's local orientation to a 90 degree rotation about the Z-axis.

Physics.createCapsule(radius: number, halfHeight: number): PhysicsGeometry

Parameters

NameTypeDefault ValueDescription
radiusnumberRequiredNo description
halfHeightnumberRequiredDistance from the origin to the centre of the end caps.

Returns

NameTypeDescription
capsulePhysicsGeometryNo description

Physics.createBox

Creates a box geometry with the given half extents along the geometry's local axes.

Physics.createBox(halfExtents: vector): PhysicsGeometry

Parameters

NameTypeDefault ValueDescription
halfExtentsvectorRequiredDistance from the origin to the sides of the box on each axis.

Returns

NameTypeDescription
boxPhysicsGeometryNo description

Physics.createPlane

Creates a plane geometry at the origin of the geometry's local coordinate space.

Everything below the plane (-X in the local coordinate space) is considered as colliding with it.

Physics.createPlane(): PhysicsGeometry

Returns

NameTypeDescription
planePhysicsGeometryNo description

Functions - Joints

Physics.setJointParentFrame

Sets the position and orientation of the joint in the parent's local space.

Physics.setJointParentFrame(entity: entity, position: vector, orientation: Quaternion)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity with the joint.
positionvectorRequiredPosition relative to the parent.
orientationQuaternionRequiredOrientation relative to the parent.

Physics.setJointChildFrame

Sets the position and orientation of the joint in the child's local space.

Physics.setJointChildFrame(entity: entity, position: vector, orientation: Quaternion)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity with the joint.
positionvectorRequiredPosition relative to the child.
orientationQuaternionRequiredOrientation relative to the child.

Physics.setJointType

Sets the type of the joint, governing its degrees of freedom.

Physics.setJointType(entity: entity, type: JointType)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity with the joint.
typeJointTypeRequiredType to set.

Physics.setJointMotion

Sets the motion of the joint along or about the degree of freedom.

Physics.setJointMotion(entity: entity, degreeOfFreedom: DegreeOfFreedom, motion: JointMotion)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity with the joint.
degreeOfFreedomDegreeOfFreedomRequiredLinear or angular degree of freedom to modify.
motionJointMotionRequiredType of motion.

Physics.setJointLimits

Sets the limits of the joint's motion along or about the degree of freedom. Does nothing unless the joint motion is set to Limited.

Physics.setJointLimits(entity: entity, degreeOfFreedom: DegreeOfFreedom, min: number, max: number)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity with the joint.
degreeOfFreedomDegreeOfFreedomRequiredLinear or angular degree of freedom to modify.
minnumberRequiredMinimum translation along or rotation about the degree of freedom.
maxnumberRequiredMaximum translation along or rotation about the degree of freedom.

Functions - Mass & Inertia

Physics.getMass

Gets the mass of a rigid-body entity or collider.

Physics.getMass(entityOrCollider: entity | Collider): number

Parameters

NameTypeDefault ValueDescription
entityOrColliderentity | ColliderRequiredThe entity or collider to get the mass of.

Returns

NameTypeDescription
massnumberThe mass of the object.

Physics.setMass

Sets the mass of a rigid-body entity or collider.

You should update the inertia tensor when modifying the mass of a rigid-body. You can either calculate this by hand, or use the helper methods setMassAndUpdateInertia and updateMassAndInertiaFromColliders.

Physics.setMass(entityOrCollider: entity | Collider, mass: number)

Parameters

NameTypeDefault ValueDescription
entityOrColliderentity | ColliderRequiredThe entity or collider to set the mass of.
massnumberRequiredThe mass to set.

Physics.getCentreOfMass

Gets the centre of mass of a rigid-body entity or collider, in local space.

Physics.getCentreOfMass(entityOrCollider: entity | Collider): vector

Parameters

NameTypeDefault ValueDescription
entityOrColliderentity | ColliderRequiredThe entity or collider to get the centre of mass of.

Returns

NameTypeDescription
centreOfMassvectorThe centre of mass of the object.

Physics.setCentreOfMass

Sets the mass of a rigid-body entity or collider.

You should update the inertia tensor when modifying the centre of mass of a rigid-body. You can either calculate this by hand, or use the helper methods setMassAndUpdateInertia and updateMassAndInertiaFromColliders.

Physics.setCentreOfMass(entityOrCollider: entity | Collider, centreOfMass: vector)

Parameters

NameTypeDefault ValueDescription
entityOrColliderentity | ColliderRequiredThe entity or collider to set the centre of mass of.
centreOfMassvectorRequiredThe centre of mass to set.

Physics.getInertiaDiagonal

Gets the diagonal inertia tensor of an entity's rigid-body

Physics.getInertiaDiagonal(entity: entity): vector

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to get the inertia diagonal of.

Returns

NameTypeDescription
inertiaDiagonalvectorThe diagonal inertia tensor.

Physics.setInertiaDiagonal

Sets the diagonal inertia tensor of an entity's rigid-body. In most cases you should use the setMassAndUpdateInertia and updateMassAndInertiaFromColliders methods instead.

Physics.setInertiaDiagonal(entity: entity, inertiaDiagonal: vector)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to set the inertia diagonal of.
inertiaDiagonalvectorRequiredThe diagonal inertia tensor.

Physics.getInertiaOrientation

Gets the orientation in which the diagonal inertia tensor of an entity's rigid-body applies.

Physics.getInertiaOrientation(entity: entity): Quaternion

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to get the inertia orientation of.

Returns

NameTypeDescription
inertiaOrientationQuaternionThe orientation of the inertia tensor.

Physics.setInertiaOrientation

Sets the orientation in which the diagonal inertia tensor of an entity's rigid-body applies. In most cases you should use the setMassAndUpdateInertia and updateMassAndInertiaFromColliders methods instead.

Physics.setInertiaOrientation(entity: entity, inertiaOrientation: Quaternion)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to set the inertia orientation of.
inertiaOrientationQuaternionRequiredThe orientation of the inertia tensor.

Physics.setMassAndUpdateInertia

Sets the mass properties of an entity's rigid-body and updates the inertia tensor to match.

This method assumes a uniform density of 1 for all attached colliders. For rigid-bodies of mixed density, use updateMassAndInertiaFromColliders or calculate the inertia tensor by hand.

Physics.setMassAndUpdateInertia(entity: entity, mass: number, centreOfMass: vector)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to set the mass properties of.
massnumberRequiredTotal mass of the rigid-body across all colliders.
centreOfMassvectorRequiredOverall centre of mass of the rigid-body, in local space.

Physics.updateMassAndInertiaFromColliders

Updates the mass and inertia of an entity's rigid-body to match its attached colliders.

Physics.updateMassAndInertiaFromColliders(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to update the mass and inertia of.

Functions - Rigid-Bodies

Physics.makeRigidStatic

Adds a static rigid-body to an entity.

Physics.makeRigidStatic(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to make a static rigid-body.

Physics.makeRigidDynamic

Adds a dynamic rigid-body to an entity.

Physics.makeRigidDynamic(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to make a dynamic rigid-body.

Physics.isRigidStatic

Checks whether the entity is a static rigid-body.

Physics.isRigidStatic(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to check.

Returns

NameTypeDescription
isRigidStaticbooleanWhether the entity is a static rigid-body.

Physics.isRigidDynamic

Checks whether the entity is a dynamic rigid-body. This includes articulation links.

Physics.isRigidDynamic(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to check.

Returns

NameTypeDescription
isRigidDynamicbooleanWhether the entity is a dynamic rigid-body.

Functions - Scene Queries

Physics.raycast

Traces a ray along a given direction up to an (optional) max distance.

Physics.raycast(origin: vector, direction: vector, maxDistance?: number, options?: RaycastOptions): RaycastResult

Parameters

NameTypeDefault ValueDescription
originvectorRequiredStarting point of the ray.
directionvectorRequiredDirection along which to trace the ray.
maxDistancenumber?nilOptional maximum distance to trace before returning a miss.
optionsRaycastOptions?nilSee documentation for RaycastOptions. Pass nil to use all defaults.

Returns

NameTypeDescription
resultRaycastResultSee documentation for RaycastResult.

Physics.sweep

Sweeps a geometry along a given direction up to an (optional) max distance.

An optional 'skin' or contact offset can be defined around the geometry to avoid issues resulting from floating point imprecision. Contacts will be generated if any part of the geometry or skin hit another object.

Physics.sweep(geometry: PhysicsGeometry, origin: vector, orientation: Quaternion, direction: vector, maxDistance?: number, skin?: number, options?: RaycastOptions): RaycastResult

Parameters

NameTypeDefault ValueDescription
geometryPhysicsGeometryRequiredGeometry to sweep.
originvectorRequiredStarting point of the geometry.
orientationQuaternionRequiredOrientation of the geometry in world space.
directionvectorRequiredDirection along which to sweep the geometry.
maxDistancenumber?nilOptional maximum distance to sweep before returning a miss.
skinnumber?"0"Optional 'skin' around the geometry to start generating intersections in.
optionsRaycastOptions?nilSee documentation for RaycastOptions. Pass nil to use all defaults.

Returns

NameTypeDescription
resultRaycastResultSee documentation for RaycastResult.

Physics.overlap

Finds all objects overlapping a geometry.

Physics.overlap(geometry: PhysicsGeometry, origin: vector, orientation: Quaternion, options?: OverlapOptions): entity[]

Parameters

NameTypeDefault ValueDescription
geometryPhysicsGeometryRequiredGeometry to test with.
originvectorRequiredPosition of the geometry.
orientationQuaternionRequiredOrientation of the geometry.
optionsOverlapOptions?nilSee documentation for OverlapOptions. Pass nil to use all defaults.

Returns

NameTypeDescription
entitiesentity[]Entities overlapping the geometry.

Functions - Scene

Physics.addToScene

Adds the entity's rigid-body to the physics scene, making it active in collision detection and scene queries. Note that articulations cannot be modified after being added to the scene.

Physics.addToScene(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to add.

Physics.removeFromScene

Removes the entity's rigid-body from the physics scene, making it inactive in collision detection and scene queries.

Physics.removeFromScene(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to remove.

Physics.isInScene

Checks whether the entity's rigid-body has been added to the physics scene.

Physics.isInScene(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to check.

Returns

NameTypeDescription
isInScenebooleanWhether the entity is in the scene.

Functions - Sleep & Wake

Physics.wake

Forces the entity's rigid-body to wake up. The physics engine will pause the simulation of rigid-bodies which have not significantly changed their state for a period of time, and will wake them automatically if another object interacts with them.

Physics.wake(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to wake.

Physics.sleep

Forces the entity's rigid-body to sleep, pausing its simulation until awoken manually or by another object.

Physics.sleep(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to sleep.

Physics.isSleeping

Checks whether the entity's rigid-body has its simulation paused.

Physics.isSleeping(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredEntity to check.

Returns

NameTypeDescription
isSleepingbooleanWhether the entity is sleeping.

Functions - Velocity & Acceleration

Physics.getLinearVelocity

Gets the linear velocity of a rigid body.

Physics.getLinearVelocity(entity: entity): vector

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
velocityvectorThe linear velocity of the rigid body.

Physics.getVelocityAtPosition

Gets the velocity of a point in world space if it were attached to the rigid body, taking into account both the linear and angular velocity.

Physics.getVelocityAtPosition(entity: entity, position: vector): vector

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
positionvectorRequiredWorld space position to read the velocity of.

Returns

NameTypeDescription
velocityvectorThe velocity of the world space position.

Physics.getAngularVelocity

Gets the angular velocity of a rigid body.

Physics.getAngularVelocity(entity: entity): vector

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
velocityvectorThe angular velocity of the rigid body.

Physics.getLinearAcceleration

Gets the linear acceleration of a rigid body.

Physics.getLinearAcceleration(entity: entity): vector

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
accelerationvectorThe linear acceleration of the rigid body.

Physics.getAngularAcceleration

Gets the angular acceleration of a rigid body.

Physics.getAngularAcceleration(entity: entity): vector

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
accelerationvectorThe angular acceleration of the rigid body.

Types

ControllerCreateOptions

No description provided.

type ControllerCreateOptions = { shape: Physics.ControllerShape, height: number?, radius: number?, climbingMode: Physics.ClimbingMode?, sideExtent: number?, forwardExtent: number?, position: vector?, upDirection: vector?, slopeLimit: number?, nonWalkableMode: Physics.NonWalkableMode?, invisibleWallHeight: number?, maxJumpHeight: number?, contactOffset: number?, stepOffset: number?, density: number?, scaleCoefficient: number?, volumeGrowth: number? }

Properties

FieldTypeDescription
shapePhysics.ControllerShapeWhich collider to use.
heightnumber?Height of the collider. For capsules this excludes the radius of the end caps.
radiusnumber?Radius of the collider. Ignored when shape is Box.
climbingModePhysics.ClimbingMode?How the capsule interacts with obstacles taller than stepOffset.
sideExtentnumber?Size of the collider on the left/right axis. Ignored when shape is Capsule.
forwardExtentnumber?Size of the collider on the forward/backward axis. Ignored when shape is Capsule.
positionvector?Initial position of the controller's centre.
upDirectionvector?Up direction of the collider.
slopeLimitnumber?Maximum slope angle before the controller is unable to move up it (as the cosine of the angle).
nonWalkableModePhysics.NonWalkableMode?How the controller reacts to non-walkable surfaces (defined by slopeLimit).
invisibleWallHeightnumber?Set greater than 0 to automatically generate wall colliders around non-walkable surfaces.
maxJumpHeightnumber?If invisibleWallHeight is greater than 0, extends the detection range for nearby surfaces.
contactOffsetnumber?Size of the skin around the collider used to handle precision issues when detecting collisions.
stepOffsetnumber?Maximum height of an obstacle that can be walked over. Capsule controllers can still slide over obstacles taller than this, unless nonWalkableMode is Constrained.
densitynumber?Density of the underlying kinematic PhysX actor.
scaleCoefficientnumber?Scale factor of the underlying kinematic PhysX actor. Should be < 1 to avoid pushing objects through walls.
volumeGrowthnumber?Size of the region around the controller to cache. Must be between 1 and 2.

ControllerMoveResult

Contains information about what happened during Physics.moveController.

type ControllerMoveResult = { hasSideCollisions: boolean, hasTopCollisions: boolean, hasBottomCollisions: boolean }

Properties

FieldTypeDescription
hasSideCollisionsbooleanTrue if any collision events occurred this move to the controller's sides
hasTopCollisionsbooleanTrue if any collision events occurred this move to the top of the controller
hasBottomCollisionsbooleanTrue if any collision events occurred this move to the bottom of the controller

RaycastOptions

Configures raycast and sweep queries for the desired behaviour and performance. All properties can be left defaulted to sensible values, maintaining expected behaviour while minimising performance impact from the more specialised features.

type RaycastOptions = { anyHit: boolean?, dontBlock: boolean?, includeStatic: boolean?, includeDynamic: boolean?, includeTouching: boolean?, includePosition: boolean?, includeNormal: boolean?, includeUv: boolean?, includeMtd: boolean?, mask: number[]? }

Properties

FieldTypeDescription
anyHitboolean?True to end the trace early on any blocking hit, not just closest.
dontBlockboolean?Causes all intersected objects to be considered 'touching' hits, allowing the query to move through objects.
includeStaticboolean?Toggles inclusion of static rigid-bodies in the query.
includeDynamicboolean?Toggles inclusion of dynamic rigid-bodies in the query.
includeTouchingboolean?Collects hits for non-blocking objects, or all objects if dontBlock is true.
includePositionboolean?Toggles calculation of hit position on all results.
includeNormalboolean?Toggles calculation of hit normal on all results.
includeUvboolean?Toggles inclusion of face UV on results which hit a triangle mesh or height field.
includeMtdboolean?Toggles calculation of Minimum Translational Distance for initial overlaps.
masknumber[]?Four 2-byte bitwise filter masks following the PhysX convention.

RaycastResultHit

A blocking or touching hit returned from a ray or sweep scene query. The contents will depend on the RaycastOptions passed to the query method.

type RaycastResultHit = { entity: entity?, distance: vector, position: vector?, normal: vector?, uv: number[]?, hadInitialOverlap: boolean }

Properties

FieldTypeDescription
entityentity?Entity that was hit, or nil if object isn't linked to an entity.
distancevectorDistance travelled along the query's direction. MTD if includeMtd was true and the query had initial overlap.
positionvector?Hit position, or nil if includePosition was false.
normalvector?Hit normal, or nil if includeNormal was false.
uvnumber[]?Hit UV, or nil if includeUv was false or the hit object isn't a mesh.
hadInitialOverlapbooleanTrue if the query had initial overlap with an object at the origin.

RaycastResult

Result of a ray or sweep scene query.

type RaycastResult = { blockingHit: RaycastResultHit?, touchingHits: RaycastResultHit[] }

Properties

FieldTypeDescription
blockingHitRaycastResultHit?Closest blocking hit if the query generated one.
touchingHitsRaycastResultHit[]List of touching hits the query generated. Empty if no touching hits or includeTouching was false.

OverlapOptions

Configures overlap queries for the desired behaviour and performance. All properties can be left defaulted to sensible values, maintaining expected behaviour while minimising performance impact from the more specialised features.

type OverlapOptions = { includeStatic: boolean?, includeDynamic: boolean?, mask: number[]? }

Properties

FieldTypeDescription
includeStaticboolean?Toggles inclusion of static rigid-bodies in the query.
includeDynamicboolean?Toggles inclusion of dynamic rigid-bodies in the query.
masknumber[]?Four 2-byte bitwise filter masks following the PhysX convention.

Enums

ForceMode

Force modes which describe the unit of the force or torque given to addForce and addTorque.

Value
Force
Impulse
VelocityChange
Acceleration

ControllerShape

Collider shape to use for character controllers.

Value
Box
Capsule

ClimbingMode

Climbing mode to use for capsule character controllers (PhysX Docs)

Value
Easy
Constrained

NonWalkableMode

How the character controller should handle non-walkable surfaces (e.g. steep slopes)

Value
PreventClimbing
PreventClimbingAndForceSliding

JointType

Joint types governing which limits and drives are supported for the joint.

Value
Fixed
Linear
Hinge
HingeUnwrapped
BallSocket

JointMotion

Allowed motion of the joint along or about a degree of freedom.

Value
Locked
Limited
Free

DegreeOfFreedom

Degrees of freedom along or about which a joint can move.

Value
LinearX
LinearY
LinearZ
AngularX
AngularY
AngularZ

Events

"tick"

Fires every time the physics engine is ticked (at the fixed physics timestep).

Physics.addEventListener("tick", function(deltaTime) end)

Parameters

NameTypeDescription
deltaTimenumberThe time in seconds since the last physics tick (the fixed timestep).