Optional
options: { Optional
allowMakes bodies go to sleep when they've been inactive.
false
Optional
broadphase?: BroadphaseThe broadphase algorithm to use.
NaiveBroadphase
Optional
frictionGravity to use when approximating the friction max force (mumassgravity). If undefined, global gravity will be used.
Optional
gravity?: Vec3The gravity of the world.
Optional
quatSet to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.
false
Optional
quatHow often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).
0
Optional
solver?: SolverThe solver algorithm to use.
GSSolver
Time accumulator for interpolation.
Dispatched after a body has been added to the world.
Makes bodies go to sleep when they've been inactive.
false
All bodies in this world
The broadphase algorithm to use.
NaiveBroadphase
collisionMatrix
CollisionMatrix from the previous step.
Used to look up a ContactMaterial given two instances of Material.
All added contactmaterials.
All the current contacts (instances of ContactEquation) in the world.
This contact material is used if no suitable contactmaterial is found for a contact.
The default material of the bodies.
Default and last timestep sizes.
Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks.
Optional
frictionGravity to use when approximating the friction max force (mu * mass * gravity). If undefined, global gravity will be used. Use to enable friction in a World with a null gravity vector (no gravity).
The gravity of the world.
True if any bodies are not sleeping, false if every body is sleeping.
Optional
lastSet to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.
false
How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).
0
Dispatched after a body has been removed from the world.
The solver algorithm to use.
GSSolver
Number of timesteps taken since start.
The wall-clock time since simulation start.
Add a rigid body to the simulation.
If the simulation has not yet started, why recrete and copy arrays for each body? Accumulate in dynamic arrays in this case.
Adding an array of bodies should be possible. This would save some loops too
Add a constraint to the simulation.
Adds a contact material to the World
Add an event listener
The self object, for chainability.
Emit an event.
The self object, for chainability.
Step the simulation forward keeping track of last called time to be able to step the world at a fixed rate, independently of framerate.
Optional
dt: numberThe fixed time step size to use (default: 1 / 60).
Optional
maxSubSteps: numberMaximum number of fixed steps to take per function call (default: 10).
https://gafferongames.com/post/fix_your_timestep/
// Run the simulation independently of framerate every 1 / 60 ms
world.fixedStep()
Get the contact material between materials m1 and m2
The contact material if it was found.
Raycast test
Use .raycastAll, .raycastClosest or .raycastAny instead.
Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument.
Optional
from: Vec3Optional
to: Vec3Optional
options: RayOptionsOptional
callback: RaycastCallbackTrue if any body was hit.
Ray cast, and stop at the first result. Note that the order is random - but the method is fast.
Optional
from: Vec3Optional
to: Vec3Optional
options: RayOptionsOptional
result: RaycastResultTrue if any body was hit.
Ray cast, and return information of the closest hit.
Optional
from: Vec3Optional
to: Vec3Optional
options: RayOptionsOptional
result: RaycastResultTrue if any body was hit.
Remove a rigid body from the simulation.
Removes a constraint
Removes a contact material from the World.
Remove an event listener
The self object, for chainability.
Step the physics world forward in time.
There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.
The fixed time step size to use.
Optional
timeSinceLastCalled: numberThe time elapsed since the function was last called.
Optional
maxSubSteps: numberMaximum number of fixed steps to take per function call (default: 10).
// fixed timestepping without interpolation
world.step(1 / 60)
The physics world