Page 2 of 2

Re: Help with setRestitution -- weird bugs?

Posted: Thu Jun 02, 2011 10:39 am
by thelinx
Is it set to allow sleeping?

Re: Help with setRestitution -- weird bugs?

Posted: Thu Jun 02, 2011 11:51 am
by Clash
thelinx wrote:Is it set to allow sleeping?
I tried both values as you suggested but there was no difference

Re: Help with setRestitution -- weird bugs?

Posted: Fri Jun 03, 2011 1:03 am
by Robin
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.
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.

Re: Help with setRestitution -- weird bugs?

Posted: Mon Jun 06, 2011 5:40 pm
by tentus
I saw the entry in the issue tracker that bart marked as invalid. I trimmed out all the tutorial stuff and made this:

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
Click anywhere in the black to drop the ball. The problem you were having was that the "ground" did not also have a restitution of 0.