Strange Friction Behavoir

Helllo,  I was trying to work with the friction properties of some static objects and came across some weird behavior.  I swear I’ve used this property before without issues so I’m not sure if I am breaking a rule somewhere or if it’s something that needs to be reported as a bug.

In my real app the friction property doesn’t seem to have any effect at all, even if i jack it up to 10000.  In my test app below the friction actually makes the object move faster instead of the friction causing the object to slow down.

The test app just has two static objects acting as a ground and two dynamic balls.  One of the grounds has a friction of .9 while the other has it set to 0.  I then apply a small, single impulse to both balls.  You would expect the ground with friction would slow down or even stop the ball.  Instead the ball is significantly faster.  

You can copy the code below into a main.lua to see it

[lua]

local physics = require(“physics”)

physics.start();

–make ground with 0 friction,  it is the grey one on the top

local groundNoFriction = display.newRect( 0, 100, 320, 25)

groundNoFriction:setFillColor(140, 140, 140)

–leave friction at 0

physics.addBody(groundNoFriction, {density=21, friction=0.0, bounce = 0.1})

groundNoFriction.bodyType = “static”

–make ground with friction. it is the pink on the bottom

local groundFriction = display.newRect( 0, 300, 320, 25)

groundFriction:setFillColor(240, 140, 140)

–set friction to some value

physics.addBody(groundFriction, {density=21, friction=0.9, bounce = 0.1})

groundFriction.bodyType=“static”

local ball1 = display.newCircle(0, 50, 20)

ball1:setFillColor(0, 255, 255)

physics.addBody(ball1, {density=1, friction=0.3, bounce = 0.1, radius=20 })

local ball2 = display.newCircle(0, 250, 20)

ball2:setFillColor(255, 0, 255)

physics.addBody(ball2, {density=1, friction=0.3, bounce = 0.1, radius=20 })

ball1:applyLinearImpulse(1, 0)

ball2:applyLinearImpulse(1,0)

[/lua]

Well, I did some testing with polygons(squares to be exact) and the friction seems to operate normally on those.  For some reason it doesn’t really seem to achieve the desired effect on circle objects which is a shame.  

Hi @budershank,

At a quick glance running your code, this is the expected behavior. You can actually see the friction effect on the lower ball because it does that quick little jump-acceleration when it first touches the ground. This is why it actually moves faster, not slower, than the upper ball. It’s the realistic equivalent of a spinning tire hitting the ground… in that case, it would make a quick jump forward and start rolling along.

You might expect that the ball would slow down, but since the balls are allowed to roll (rotate), there’s never much contact point between the ball and the ground. Now, if you set their rotation to fixed, they will behave as you probably want them to… they just skid to an almost immediate stop. This is because that one surface is “rubbing” on the ground, instead of the ball rolling along it.

Anyway, tinker around with this, and you’ll see what I mean. The behavior I see is completely normal. :slight_smile:

Brent

P.S. - you should also specify the point (on each ball) to apply the linear impulse. Typically this will be the center point, as the final two arguments. You didn’t specify them, which is why the balls actually start out spinning. If you apply the impulse to the direct center in each case, the balls will not spin.

That makes perfect sense.  I figured it wouldn’t slow down as much due to the smaller point of contact but didn’t think of it in terms of traction.  Thanks a bunch!

With the impulse I don’t really use that in my real app.  I just needed something to start movement and took my best guess at remembering the syntax for that particular function :slight_smile:

Thanks again, that clears up a lot.

Well, I did some testing with polygons(squares to be exact) and the friction seems to operate normally on those.  For some reason it doesn’t really seem to achieve the desired effect on circle objects which is a shame.  

Hi @budershank,

At a quick glance running your code, this is the expected behavior. You can actually see the friction effect on the lower ball because it does that quick little jump-acceleration when it first touches the ground. This is why it actually moves faster, not slower, than the upper ball. It’s the realistic equivalent of a spinning tire hitting the ground… in that case, it would make a quick jump forward and start rolling along.

You might expect that the ball would slow down, but since the balls are allowed to roll (rotate), there’s never much contact point between the ball and the ground. Now, if you set their rotation to fixed, they will behave as you probably want them to… they just skid to an almost immediate stop. This is because that one surface is “rubbing” on the ground, instead of the ball rolling along it.

Anyway, tinker around with this, and you’ll see what I mean. The behavior I see is completely normal. :slight_smile:

Brent

P.S. - you should also specify the point (on each ball) to apply the linear impulse. Typically this will be the center point, as the final two arguments. You didn’t specify them, which is why the balls actually start out spinning. If you apply the impulse to the direct center in each case, the balls will not spin.

That makes perfect sense.  I figured it wouldn’t slow down as much due to the smaller point of contact but didn’t think of it in terms of traction.  Thanks a bunch!

With the impulse I don’t really use that in my real app.  I just needed something to start movement and took my best guess at remembering the syntax for that particular function :slight_smile:

Thanks again, that clears up a lot.