World

Edit

A World is an object that holds the colliders, joints, and shapes in a physics simulation.

Constructor

lovr.physics.newWorldCreate a new World.

Basics

World:destroyDestroy the World!! Muahaha!
World:raycastCast a ray through the World.
World:updateUpdate the World.

Colliders

The following functions add Colliders to the World. World:newCollider adds an "empty" Collider without any Shapes attached, whereas the other functions are shortcut functions to add Colliders with Shapes already attached to them.

World:getCollidersGet a table of all Colliders in the World.
World:newBoxColliderAdd a Collider with a BoxShape to the World.
World:newCapsuleColliderAdd a Collider with a CapsuleShape to the World.
World:newColliderAdd a Collider to the World.
World:newCylinderColliderAdd a Collider with a CylinderShape to the World.
World:newMeshColliderAdd a Collider with a MeshShape to the World.
World:newSphereColliderAdd a Collider with a SphereShape to the World.

Properties

The following functions are global properties of the simulation that apply to all new Colliders.

World:getAngularDampingGet the angular damping of the World.
World:getGravityGet the gravity of the World.
World:getLinearDampingGet the linear damping of the World.
World:getResponseTimeGet the response time of the World.
World:getStepCountGet the step count of the World.
World:getTightnessGet the tightness of joints in the World.
World:isSleepingAllowedCheck if colliders can go to sleep.
World:setAngularDampingSet the angular damping of the World.
World:setGravitySet the gravity of the World.
World:setLinearDampingSet the linear damping of the World.
World:setResponseTimeSet the response time of the World.
World:setSleepingAllowedSet whether colliders can go to sleep.
World:setStepCountSet the step count of the World.
World:setTightnessSet the tightness of joints in the World.

Collision

When the World is created using lovr.physics.newWorld, it is possible to specify a list of collision tags for the World. Colliders can then be assigned a tag. You can enable and disable collision between pairs of tags. There are also some helper functions to quickly identify pairs of colliders that are near each other and test whether or not they are colliding. These are used internally by default by World:update, but you can override this behavior and use the functions directly for custom collision behavior.

World:collideAttempt to collide two shapes.
World:computeOverlapsCompute pairs of shapes that are close to each other.
World:disableCollisionBetweenDisable collision between two tags.
World:enableCollisionBetweenEnable collision between two tags.
World:getContactsGet a list of points where a pair of shapes touch.
World:isCollisionEnabledBetweenCheck if two tags can collide.
World:overlapsIterate over pairs of nearby shapes.

Notes

Be sure to update the World in lovr.update using World:update, otherwise everything will stand still.

See also