Physics not simulating after altering tutorial program
Posted: Sat Oct 08, 2011 4:34 pm
Just downloaded this wonderful library to prototype some ideas (may even use it for the actual thing!), and have hit a snag at the get-go. I'm experimenting with the physics module and have been altering the tutorial example. I have set the world to be 1 metre per pixel as it makes things far more intuitive. The largest dynamic body that gets created is 2 metres/pixels in radius.
The issue is... the ball just sits there in the air and isn't affected by gravity. I've set gravity to be the standard constant of 9.8, but changing that to be higher didn't make any difference. The entire program is listed below - any help is appreciated. There may be some quirks of Love/Box2D that I'm missing.
Thanks in advance
The issue is... the ball just sits there in the air and isn't affected by gravity. I've set gravity to be the standard constant of 9.8, but changing that to be higher didn't make any difference. The entire program is listed below - any help is appreciated. There may be some quirks of Love/Box2D that I'm missing.
Thanks in advance
Code: Select all
function love.load ()
world = love.physics.newWorld (0, 0, 650, 650)
world:setGravity (0, 9.8)
world:setMeter (1)
objects = {}
objects.ground = {}
objects.ground.body = love.physics.newBody (world, 650/2, 625, 0, 0)
objects.ground.shape = love.physics.newRectangleShape (objects.ground.body, 0, 0, 650, 50, 0)
objects.ball = {}
objects.ball.body = love.physics.newBody (world, 650/2, 650/2, 10, 0)
objects.ball.shape = love.physics.newCircleShape (objects.ball.body, 0, 0, 2)
love.graphics.setBackgroundColor (104, 136, 248)
love.graphics.setMode (650, 650, false, true, 0)
end
function love.update (dt)
world:update (dt)
end
function love.draw ()
love.graphics.setColor (72, 160, 14)
love.graphics.polygon ("fill", objects.ground.shape:getPoints ())
love.graphics.setColor (193, 47, 14)
love.graphics.circle ("fill", objects.ball.body:getX (), objects.ball.body:getY (), objects.ball.shape:getRadius (), 10)
end