Re: Help with setRestitution -- weird bugs?
Posted: Thu Jun 02, 2011 10:39 am
Is it set to allow sleeping?
I tried both values as you suggested but there was no differencethelinx wrote:Is it set to allow sleeping?
Yeah, that's expected. A restitution of 1 means the ball keeps on bouncing forever, because the ball bounces up to the same place it was at first each time. 0.9 means every bounce is 90% of the last bounce. At the end, it keeps bouncing at smaller and smaller heights, rounding each of them to 1 pixel.Clash wrote:About 0.9, I didn't say it flies off the world, it just bounces a million times close to the ground before stopping.
Code: Select all
function love.load()
world = love.physics.newWorld(0, 0, 800, 600)
world:setGravity(0, 600)
world:setMeter(64)
bodies = {
box = love.physics.newBody(world, 400, 550, 0, 0),
ball = love.physics.newBody(world, 400, 100, 15, 0)
}
shapes = {
box = love.physics.newRectangleShape(bodies.box, 0, 0, 800, 100, 0),
ball = love.physics.newCircleShape(bodies.ball, 0, 0, 20)
}
shapes.box:setRestitution(0)
shapes.ball:setRestitution(0)
end
function love.update(dt)
dt = math.min(dt, 1/30)
world:update(dt)
end
function love.draw()
local x1, y1, x2, y2, x3, y3, x4, y4 = shapes.box:getBoundingBox()
local boxwidth = x3 - x2
local boxheight = y2 - y1
love.graphics.rectangle("fill", bodies.box:getX() - boxwidth/2, bodies.box:getY() - boxheight/2, boxwidth, boxheight)
love.graphics.circle("fill", bodies.ball:getX(), bodies.ball:getY(), shapes.ball:getRadius(), 20)
end
function love.mousereleased(x,y,button)
if y < 500 and (x > 0 or x < 600) then
bodies.ball:setPosition(x,y)
end
end