physics3d

class physics3d.world
static world()

Create a new physics world

body(type, x, y, z)

Create a new rigidbody in this world

Parameters:
  • type (enum) – The type of body, STATIC, DYNAMIC or KINEMATIC

  • x (number) – The initial x position of the new body

  • y (number) – The initial y position of the new body

  • z (number) – The initial z position of the new body

Returns:

The newly created body

Return type:

physics3d.body

step([deltaTime])

Steps the simulation by deltaTime

draw()

Draws a debug representation of the physics world using primitive shapes

raycast(origin, direction, distance[, mask])

Performs a raycast on the physics world from origin in the direction of direction for the distance of distance

The raycast itself is filtered by the optional mask parameter, a bitfield which is compared to collider categories

Parameters:
  • origin (vec3) – The origin of the ray

  • direction (vec3) – The direction of the ray

  • distance (number) – The maximum distance for the ray to travel

Returns:

The raycast hit info or nil is no collider was hit

Return type:

physics3d.rayHit

sphereCast(origin, direction, distance, radius[, mask])

Performs a sphere cast on the physics world from origin in the direction of direction for the distance of distance

The sphere cast itself is filtered by the optional mask parameter, a bitfield which is compared to collider categories

Parameters:
  • origin (vec3) – The origin of the ray

  • direction (vec3) – The direction of the ray

  • distance (number) – The maximum distance for the ray to travel

  • radius – The radius of the sphere used to perform the cast

Returns:

The raycast hit info or nil is no collider was hit

Return type:

physics3d.rayHit

gravity: vec3

The current gravity vector for this world

class physics3d.body

A three dimensional rigidbody that simulated within a physics3d.world. Used to simulate both dynamic and static objects, responding to physical forces, collisions and physics queries (i.e. raycast, queryBox, etc…)

destroy()

Destroys this body, removing it from the world in the next simluation step

sphere(radius[, offsetX, offsetY, offsetZ])

Creates and attaches a sphere collider to this body

Parameters:
  • radius (number) – The radius of the circle

  • offsetX – The local x offset of the circle

  • offsetY – The local y offset of the circle

  • offsetZ – The local y offset of the circle

Returns:

The new circle collider

Return type:

physics3d.sphere

box(halfWidth, halfHeight, halfDepth[, offsetX, offsetY, offsetZ])

Creates and attaches a box collider to this body

Parameters:
  • halfWidth – half width of the box

  • halfHeight – half height of the box

  • halfDepth – half depth of the box

  • offsetX – The local x offset of the circle

  • offsetY – The local y offset of the circle

  • offsetZ – The local y offset of the circle

Returns:

The new box collider

Return type:

physics3d.box

capsule(radius, height[, offsetX, offsetY, offsetZ])

Creates and attaches a capsule collider to this body

Parameters:
  • radius (number) – The radius of the capsule

  • radius – The height of the capsule

  • offsetX – The local x offset of the circle

  • offsetY – The local y offset of the circle

  • offsetZ – The local y offset of the circle

Returns:

The new capsule collider

Return type:

physics3d.polygon

mesh(mesh[, convex])

Creates and attaches a mesh collider to this body

Returns:

The new capsule collider

Return type:

physics3d.mesh

hinge(anchor, axis)
hinge(other, anchor, axis)
hinge(other, anchorA, axisA, anchorB, axisB)

Creates and attaches a hinge joint to this body. When no other body is provided the hinge joint attaches to the world itself

For two-body joints when one anchor and axis is provided, it will be interpreted as a world space location, which will attach to the relative locations of both bodies

When two anchors and axes are provided (anchorA / axisA and anchorB / axisB) are provided, they will be interpreted in local space and attach to those locations directly

Parameters:
  • other (physics3d.body) – The other body to connect to the joint

  • anchor (vec3) – The world-space anchor for one or two-body hinges

  • axis – The world-space axis for one or two-body hinges

  • anchorA (vec3) – The local-space anchor for the main body

  • axisA (vec3) – The local-space axis for the main body

  • anchorB (vec3) – The local-space anchor for the attached body

  • axisB (vec3) – The local-space axis for the attached body

Returns:

The new hinge joint

Return type:

physics3d.hinge

applyForce(force[, worldPoint])

Applies a force to this body over time (non-instantanious). Ideal for physical effects such as wind, bouyancy and springs

The optional parameter worldPoint can be used to apply forces to a specific location in world-space

Parameters:
  • force (vec2) – The force to apply

  • worldPoint (vec3) – The world-space location to apply the force at

  • force – The force vector to apply

applyTorque(torque)
Parameters:

torque (vec3) – The torque vector to apply

applyLinearImpulse(impulse)
Parameters:

impulse (vec3) – The linear impulse to apply

applyAngularImpulse(impulse)
Parameters:

impulse (vec3) – The angular impulse to apply

worldPoint(localPoint)

Transforms localPoint from local space to world space in respect to this body

Parameters:

localPoint (vec3) – The local space point to transform

Return type:

vec3

worldVector(localVector)

Transforms localVector from world space to local space in respect to this body

Parameters:

localVector (vec3) – The world space vector to transform

Return type:

vec3

localPoint(worldPoint)

Transforms worldPoint from world space to local space in respect to this body

Parameters:

worldPoint (vec3) – The world space point to transform

Return type:

vec3

localVector(worldVector)

Transforms worldVector from world space to local space in respect to this body

Parameters:

worldVector (vec3) – The world space vector to transform

Return type:

vec3

velocityAtLocalPoint(localPoint)

Samples the velocity of the body at localPoint in local space

Useful for determining velocity on a body at a specific location for calculating effects, sounds and damage during collisions

Parameters:

localPoint (vec3) – The local point to sample velocity from

Return type:

vec3

velocityAtWorldPoint(worldPoint)

Samples the velocity of the body at worldPoint in world space

Useful for determining velocity on a body at a specific location for calculating effects, sounds and damage during collisions

Parameters:

worldPoint (vec3) – The world point to sample velocity from

Return type:

vec3

destroyed: boolean

Flag indicating that this body has already been destroyed

position: vec3

The position of this body in the simulated world

mass: number

The mass of this body in kilograms

inertia: number (readonly)

The interial tensor in kg m^2

linearDamping: number

The amount of linear damping to apply, slowing velocity proportionally over time

angularDamping: number

The amount of linear damping to apply, slowing rotation propotionally over time

sleepingAllowed: boolean

Flag for allowing sleeping for this body

awake: boolean

Flag for the current awake state of this body, set to true to wake immediately

enabled: boolean

Flag for whether simulation is enabled

constraints: bitfield

Flags to lock movement and rotation along each axis, using the following flags:

  • physics3d.freezePositionX

  • physics3d.freezePositionY

  • physics3d.freezePositionZ

  • physics3d.freezeRotationX

  • physics3d.freezeRotationY

  • physics3d.freezeRotationZ

  • physics3d.freezeRotation

  • physics3d.freezePosition

  • physics3d.freezeAll

These flags can also be combined, i.e. myBody.constraints = physics3d.freezePositionX | physics3d.freezeRotation

bullet: boolean

Continuous physics switch for this body, used to prevent tunneling for fast moving objects

class physics3d.collider

TODO

class physics3d.sphere: collider

TODO

class physics3d.box: collider

TODO

class physics3d.capsule: collider

TODO

class physics3d.mesh: collider

TODO

class physics3d.cylinder: collider

TODO

class physics3d.cone: collider

TODO

class physics3d.joint

TODO

class physics3d.hinge: joint

TODO

class physics3d.slider: joint

TODO

class physics3d.ballSocket: joint

TODO

class physics3d.coneTwist: joint

TODO

class physics3d.generic: joint

TODO

class physics3d.weld: joint

TODO

class physics3d.rayHit
point: vec3

The world position of the raycast hit location

normal: vec3

The world normal of the raycast hit location

fraction: number

The fraction of the total ray distance travelled before a hit was detected

triangleIndex: integer

The index of the triangle hit (if we hit a mesh collider)

uv: vec2

The uv coorindate of the triangle hit (if we hit a mesh collider)

barycentric: vec2

The barycentric coorindate of the triangle hit (if we hit a mesh collider)

collider: physics3d.collider

The collider that was hit by the ray

body: physics3d.body

The body of the collider that was hit by the ray