World

expect class World(def: WorldDef)

A physics world that contains bodies and manages simulation.

Parameters

def

World configuration. Use WorldDef() for defaults or customize as needed.

Constructors

Link copied to clipboard
expect constructor(def: WorldDef)

Properties

Link copied to clipboard
expect val awakeBodyCount: Int

Get the number of awake bodies.

Link copied to clipboard
expect var gravity: Vec2

The gravity vector.

Link copied to clipboard

The hit event speed threshold, usually in m/s. Collisions above this speed generate hit events.

Link copied to clipboard

Enable or disable continuous collision.

Link copied to clipboard

Enable or disable sleeping.

Link copied to clipboard
expect val isValid: Boolean

Check if this world reference is valid.

Link copied to clipboard

The maximum linear speed, usually in m/s.

Link copied to clipboard

The restitution speed threshold, usually in m/s. Collisions above this speed have restitution applied.

Link copied to clipboard
expect var userData: Long

User data stored as a Long. Can be used as a key in a Map for associating arbitrary objects with this world.

Functions

Link copied to clipboard
expect fun castMover(mover: Capsule, translation: Vec2, filter: QueryFilter = QueryFilter.Default): Float

Cast a capsule mover and return the closest hit fraction. This is a simplified query for character movement.

Link copied to clipboard
expect fun castRay(origin: Vec2, translation: Vec2, filter: QueryFilter = QueryFilter.Default, callback: (Shape, Vec2, Vec2, Float) -> Float): TreeStats

Cast a ray against the world. The callback is called for each shape hit. Return the fraction to clip the ray for the next hit, 0 to terminate, or 1 to not clip.

Link copied to clipboard
expect fun castRayClosest(origin: Vec2, translation: Vec2, filter: QueryFilter = QueryFilter.Default): RayResult

Cast a ray and return the closest hit.

Link copied to clipboard
expect fun castShape(proxy: ShapeProxy, translation: Vec2, filter: QueryFilter = QueryFilter.Default, callback: (Shape, Vec2, Vec2, Float) -> Float): TreeStats

Cast a shape against the world. The callback is called for each shape hit.

Link copied to clipboard
expect fun collideMover(mover: Capsule, filter: QueryFilter = QueryFilter.Default, callback: (Shape, PlaneResult) -> Boolean)

Collide a capsule mover with the world. The callback receives collision planes.

Link copied to clipboard
expect fun createBody(def: BodyDef): Body

Create a new body in this world.

Link copied to clipboard

Create a distance joint.

Link copied to clipboard

Create a filter joint to disable collision between two bodies. This is more efficient than using collision filtering when you need to disable collision between a specific pair of bodies.

Link copied to clipboard

Create a motor joint.

Link copied to clipboard

Create a mouse joint.

Link copied to clipboard

Create a prismatic (slider) joint.

Link copied to clipboard

Create a revolute (hinge) joint.

Link copied to clipboard

Create a weld joint.

Link copied to clipboard

Create a wheel joint.

Link copied to clipboard
expect fun destroy()

Destroy this world and all its contents. After calling this, the world should not be used.

Link copied to clipboard
expect fun destroyBody(body: Body)

Destroy a body and remove it from the world.

Link copied to clipboard
expect fun destroyJoint(joint: Joint)

Destroy a joint.

Link copied to clipboard
expect fun explode(explosionDef: ExplosionDef)

Apply a radial explosion.

Link copied to clipboard

Get body move events from the last simulation step. Body move events indicate bodies that have moved and can be used to update game objects.

Link copied to clipboard

Get contact events from the last simulation step.

Link copied to clipboard
expect fun getCounters(): Counters

Get world simulation counters for diagnostics.

Link copied to clipboard

Get sensor events from the last simulation step.

Link copied to clipboard
expect fun overlapAABB(aabb: AABB, filter: QueryFilter = QueryFilter.Default, callback: (Shape) -> Boolean): TreeStats

Query an AABB for overlapping shapes. The callback is called for each shape found. Return true from the callback to continue the query, false to stop.

Link copied to clipboard
expect fun overlapShape(proxy: ShapeProxy, filter: QueryFilter = QueryFilter.Default, callback: (Shape) -> Boolean): TreeStats

Query for shapes overlapping a shape proxy. The callback is called for each shape found. Return true from the callback to continue the query, false to stop.

Link copied to clipboard
expect fun setContactTuning(hertz: Float, dampingRatio: Float, pushSpeed: Float)

Adjust contact tuning parameters.

Link copied to clipboard
expect fun setCustomFilterCallback(callback: (Shape, Shape) -> Boolean?)

Set a custom collision filter callback. This is called before contact creation. Return false to disable a contact between two shapes.

Link copied to clipboard
expect fun setFrictionCallback(callback: (Float, Int, Float, Int) -> Float?)

Set a custom friction callback for computing friction between two surfaces.

Link copied to clipboard
expect fun setPreSolveCallback(callback: (Shape, Shape) -> Boolean?)

Set a pre-solve callback. This is called after contact creation but before the solver. Return false to disable the contact for this step.

Link copied to clipboard
expect fun setRestitutionCallback(callback: (Float, Int, Float, Int) -> Float?)

Set a custom restitution callback for computing restitution between two surfaces.

Link copied to clipboard
expect fun step(timeStep: Float, subStepCount: Int = 4)

Advance the simulation by one time step.