Page 1 of 1

[Help] Shape's Frictions

Posted: Tue Dec 12, 2017 2:30 pm
by Fireicefly
Hey guys, i'm a new LOVE user and i've got a problem : frictions didn't work with this code :

Code: Select all

function love.load()
	love.window.setMode(800, 600, {resizable=false})
	love.physics.setMeter(64)
	world = love.physics.newWorld(0, 64*9.81, true)
	objects = {}
	objects.ground = {}
	objects.ground.body = love.physics.newBody(world, 0,550, "static")
	objects.ground.shape = love.physics.newRectangleShape(400, 25, 800, 50)
	objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape)
	objects.ground.fixture:setFriction(1)
	
	objects.ball = {}
	objects.ball.body = love.physics.newBody(world, 400, 300, "dynamic")
	objects.ball.shape = love.physics.newCircleShape(100)
	objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1)
	objects.ball.fixture:setRestitution(0.6)
	objects.ball.fixture:setFriction(1)
end

function love.update(dt)
	world:update(dt)
	if love.keyboard.isDown("left") then
		objects.ball.body:applyForce(-400, 0)
	end
	if love.keyboard.isDown("right") then
		objects.ball.body:applyForce(400, 0)
	end
end

function love.draw()
	love.graphics.setColor(255, 0, 0, 100)
	love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
	love.graphics.setColor(255,255,255,80)
	love.graphics.circle("line", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
end

 
I applied to both fixture a friction of 1 but the ball still rolls as if it was on the ice.
Thank you for the help !

Re: [Help] Shape's Frictions

Posted: Sat Jul 21, 2018 7:25 pm
by Morfeu
It's quite a late answer. I hope it still can be useful for you or somebody else facing the same issue.

Friction is actually working in your code, but the ball will roll on the ground without losing momentum. If rather you use a shape that does not roll smoothly (e.g. a square), the object will actually stop quite quickly due to the friction.

In order to make the circle shape to lose momentum while rolling, you'd better apply a rolling resistance. However, Löve does not support it yet. Instead, you can apply an angular damping like the following:

Code: Select all

objects.ball.body:setAngularDamping(0.5) 
Tweaking it's parameter correctly can achieve good results.