lovr.physics.newWorld

Creates a new physics World, which tracks the overall physics simulation, holds collider objects, and resolves collisions between them.

world = lovr.physics.newWorld(xg, yg, zg, allowSleep, tags)

Arguments

NameTypeDefaultDescription
xgnumber0The x component of the gravity force.
ygnumber-9.81The y component of the gravity force.
zgnumber0The z component of the gravity force.
allowSleepbooleantrueWhether or not colliders will automatically be put to sleep.
tagstable{}A list of collision tags colliders can be assigned to.

Returns

NameTypeDescription
worldWorldA whole new World.

Notes

A World must be updated with World:update in lovr.update for the physics simulation to advance.

Example

Create a new world, add a collider to it, and update it, printing out its position as it falls.

function lovr.load()
  world = lovr.physics.newWorld()
  box = world:newBoxCollider()
end

function lovr.update(dt)
  world:update(dt)
  print(box:getPosition())
end

See also