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.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.

Physics.getMass

Gets the mass of a rigid body.

Physics.getMass(entity: entity): number

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.

Returns

NameTypeDescription
massnumberThe mass of the rigid body.

Physics.setMass

Sets the mass of a rigid body.

Physics.setMass(entity: entity, mass: number)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity with the rigid body.
massnumberRequiredThe mass to set.

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.

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.

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.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.

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

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

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.

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

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

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).