Gets the Jolt Backend instance. This is useful, when components are not sufficient and you wish to access Jolt's API directly.
Note, this will be null
, if the backend runs in a web worker. In this case you don't have
access to the instance.
Gets the fixed timestep size that the physics world is stepping with. This was set via JoltInitSettings.fixedStep.
Allows to pause/unpause physics update. Useful, when you have some UI popup and want to freeze the game world, but still be able to interact with the application.
If true
, will pause the physics world update.
Gets the update event used to step physics.
Sets the update event to step physics.
A callback function to call when all rigid and soft bodies fall asleep. It will be called every frame, while the bodies are not active.
Note, that if a kinematic body has an BodyComponent.isometryUpdate set to
ISOMETRY_DEFAULT
or ISOMETRY_FRONT_TO_BACK
, then the body will have its transforms get
auto-updated in physics world every frame, preventing it from falling asleep. If you need
this callback while using a kinematic body, then set its isometry update to
ISOMETRY_BACK_TO_FRONT
and control its transforms via component's move methods, e.g.
BodyComponent.teleport, BodyComponent.linearVelocity etc. That will stop
the frontend from sending isometry updates every frame and will rely on you setting its
transforms when needed.
Feature is disabled when web worker is used.
Callback function to execute.
Creates a raycast query to the physics world.
Note, that a callback function is optional when running physics on main thread. When using a web worker, the method will not return any results directly, but will send them to your callback function instead once the frontend gets the worker's response. It also means that when using a web worker a callback function is no longer optional and is required.
World point where the ray originates from.
Non-normalized ray direction. The magnitude is ray's distance.
Optional
callback: null | ((results: CastResult[]) => void) = nullA callback function that will accept the raycast results.
Interface
An array with query results. An empty array if no results.
Optional
opts: null | CastRaySettings = nullSettings object to customize the query.
null
, if not using CastRaySettings.immediate mode.Creates a shapecast query to the physics world.
Note, that a callback function is optional when running physics on main thread. When using a web worker, the method will not return any results directly, but will send them to your callback function instead once the frontend gets the worker's response. It also means that when using a web worker a callback function is no longer optional and is required.
Shape index number. Create one using createShape.
World point where the cast is originated from.
Shape rotation.
Non-normalized ray direction. The magnitude is ray's distance.
Optional
callback: null | ((results: CastResult[]) => void) = nullA callback function that will accept the raycast results.
Interface
An array with query results. An empty array if no results.
Optional
opts: null | CastShapeSettings = nullSettings object to customize the query.
null
, if not using CastShapeSettings.immediate mode.import { SHAPE_SPHERE } from './physics.dbg.mjs';
// Do a 10 meters cast with a 0.3 radius sphere from (0, 5, 0) straight down.
const shapeIndex = app.physics.createShape(SHAPE_SPHERE, { radius: 0.3 });
const pos = new Vec3(0, 5, 0);
const dir = new Vec3(0, -10, 0);
const results = app.physics.castShape(shapeIndex, pos, Quat.IDENTITY, dir, null, {
ignoreSensors: true
});
if (results.length > 0) {
// do something with the results
}
Check if a world point is inside any body shape. For this test all shapes are treated as if they were solid. For a mesh shape, this test will only provide sensible information if the mesh is a closed manifold.
Note, that a callback function is optional when running physics on main thread. When using a web worker, the method will not return any results directly, but will send them to your callback function instead once the frontend gets the worker's response. It also means that when using a web worker a callback function is no longer optional and is required.
World position to test.
Optional
callback: null | ((results: Entity[]) => void) = nullFunction to take the query results.
Optional
opts: null | QuerySettings = nullQuery customization settings.
null
, if not using QuerySettings.immediate mode.Gets all entities that collide with a given shape.
Note, that a callback function is optional when running physics on main thread. When using a web worker, the method will not return any results directly, but will send them to your callback function instead once the frontend gets the worker's response. It also means that when using a web worker a callback function is no longer optional and is required.
Shape index created with createShape.
World position of the shape.
Optional
rotation: Quat = Quat.IDENTITYWorld rotation of the shape.
Optional
callback: null | ((results: CollideShapeResult[]) => void) = nullCallback function that will take the query results.
Interface
An array with query results. An empty array if no results.
Optional
opts: null | CollideShapeSettings = nullQuery customization settings.
null
, if not using CollideShapeSettings.immediate mode.import { SHAPE_BOX } from './physics.dbg.mjs';
// create a box with a half extent (1, 1, 1) meters (now we can use the same shape for
// different casts, but simply modifying its scale during the cast)
const shapeIndex = app.physics.createShape(SHAPE_BOX, { halfExtent: Vec3.ONE });
// get all entities that intersect a box with half extent (0.2, 0.5, 0.2) at world position
// (0, 10, 0)
const scale = new Vec3(0.2, 0.5, 0.2);
const pos = new Vec3(0, 10, 0);
const results = app.physics.collideShape(shapeIndex, pos, Quat.IDENTITY, null, { scale });
if (results.length > 0) {
// do something with the results
}
Allows to create collision groups. Note, that collision groups are more expensive than broadphase layers.
The groups are created by giving an array of numbers, where each element adds a group and its number represents the count of subgroups in it.
Collision groups.
Optional
opts: ImmediateSettingsCustomization options.
// Create `2` groups. The first group has `3` subgroups, the second `5`.
app.physics.createGroups([3, 5]);
For additional information, refer to Jolt's official documentation on Collision Filtering.
Creates a shape in the physics backend. Note, that the shape is not added to the physics world after it is created, so it won't affect the simulation.
This is useful, when you want to use a shape for a shapecast, or want your kinematic character controller to change current shape (e.g. standing, sitting, laying, etc).
Once you no longer need the shape, you must destroyShape to avoid memory leaks.
Shape type number (ShapeComponent.shape).
Optional
opts: ShapeSettings = {}Shape settings.
Shape index (uint).
import { SHAPE_CAPSULE } from './physics.dbg.mjs';
// create a 2m high and 0.6m wide capsule.
const shapeIndex = app.physics.createShape(SHAPE_CAPSULE, {
halfHeight: 1,
radius: 0.3
});
ShapeComponent.shape for available shape type options.
Destroys a shape that was previously created with createShape.
Shape index number.
Optional
opts: ImmediateSettings = {}Customization options.
Allows to manually interpolate the bodies when you step physics yourself. Requires
JoltInitSettings.manualStep and JoltInitSettings.useMotionStates to be
true
. This will update entities positions and rotations to their interpolated
representations.
See step for example usage.
Fixed step fraction to interpolate to.
Whether to use new position and rotation of a body as a base for interpolation.
Removes a callback that was set via addIdleCallback.
Destroys an existing physics system in Jolt backend and creates a new one. You may want to use this for a deterministic start.
Note, that you should destroy all existing entities with physics components before calling a reset.
Allows to manually step the physics, if you control the time yourself. Requires
JoltInitSettings.manualStep to be true
. Will always step once with
JoltInitSettings.fixedStep size. This will update the entities positions and
rotations to the same as they are in the physics world.
Note: If you use JoltInitSettings.useMotionStates (true
by default), the
isometries of the entities will not be updated to the physics world positions. They will be
read from their motion states. In order to update the motion state, and as a result the
entity isometry, you need to call interpolate.
Toggles a collision between 2 subgroups inside a group.
Group index number.
First subgroup number.
Second subgroup number.
true
to enable, false
to disable collision.
Optional
opts: ImmediateSettingsQuery customization options.
Jolt Manager is responsible to handle the Jolt Physics backend.