Help with setRestitution -- weird bugs?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Help with setRestitution -- weird bugs?

Post by thelinx »

Is it set to allow sleeping?
Clash
Prole
Posts: 6
Joined: Wed Jun 01, 2011 6:08 pm

Re: Help with setRestitution -- weird bugs?

Post by Clash »

thelinx wrote:Is it set to allow sleeping?
I tried both values as you suggested but there was no difference
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Help with setRestitution -- weird bugs?

Post 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.
Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Help with setRestitution -- weird bugs?

Post 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.
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: No registered users and 76 guests