Module
love.physics
The physics module is capable of deteting collisions between objects, and simulate a realistic responses.

The module is currently based on Box2D. The original naming scheme is kept, and most of the functionality avaliable in Box2D is avaliable in LÖVE, so you can also take a look at the Box2D User Manual for detailed documentation.

Some limitations to keep in mind:
  • Only convex shapes are supported.
  • The max vertex count for on a single polygon is 8.
  • There are 16 shape categories.
Types
World Contains all Bodies and joints.
Contact Represents a contact point between two shapes.
Body A Body is a physical entity with position and orientation.
CircleShape A simple circle which can be attatched to Bodies.
PolygonShape Convex polygon which can be attatched to Bodies.
DistanceJoint Maintains a certain distance between Bodies.
RevoluteJoint Allow two Bodies to revolve around a shared point.
PrismaticJoint Restricts relative motion between Bodies to one shared axis.
MouseJoint For controlling objects with the mouse.
Examples
Example 100: Mini Physics
  1. -- Example: Mini Physics 
  2.  
  3. function load() 
  4.  
  5.    -- Create a world with size 2000 in every direction. 
  6.    world = love.physics.newWorld(20002000
  7.    world:setGravity(050
  8.  
  9.    -- Create the ground body at (0, 0) with mass 0. 
  10.    ground = love.physics.newBody(world, 000
  11.     
  12.    -- Create the ground shape at (400,500) with size (600,10). 
  13.    ground_shape = love.physics.newRectangleShape(ground, 40050060010
  14.  
  15.    -- Load the image of the ball. 
  16.    ball = love.graphics.newImage("images/love-ball.png"
  17.  
  18.    -- Create a Body for the circle. 
  19.    body = love.physics.newBody(world, 400200
  20.     
  21.    -- Attatch a shape to the body. 
  22.    circle_shape = love.physics.newCircleShape(body, 28
  23.     
  24.    -- Calculate the mass of the body based on attatched shapes. 
  25.    -- This gives realistic simulations. 
  26.    body:setMassFromShapes() 
  27.  
  28. end 
  29.  
  30. function update(dt) 
  31.    -- Update the world. 
  32.    world:update(dt) 
  33. end 
  34.  
  35. function draw() 
  36.    -- Draws the ground. 
  37.    love.graphics.polygon(love.draw_line, ground_shape:getPoints()) 
  38.  
  39.    -- Draw the circle. 
  40.    love.graphics.draw(ball,body:getX(), body:getY(), body:getAngle()) 
  41. end 
  42.  
  43. function keypressed(k) 
  44.    if k == love.key_space then 
  45.       -- Apply a random impulse 
  46.       body:applyImpulse(100000-math.random(0200000), 0
  47.    end 
  48. end 
Copyright © 2006-2008 LÖVE Development Team.