[Box2D] Best way to implement rolling friction/resistance?

I just realized over the weekend that apparently, Box2D doesn’t support friction for circles. I discovered this when I was controlling the ball for my game, left it for a while because I had something to do, then when I came back, it was still rolling.

Upon googling, it really is because Box2D doesn’t support rolling resistance. The most suggested solution is to apply damping on the body so that it gradually slows down. I did this and it works well for the most part. However, it only works nicely for flat surfaces.

For downward slopes, one would expect the ball to roll increasingly faster as it rolls down, but it doesn’t. The speed rolling down seems constant from top to bottom, and I think the damping has something to do with it.

So my question is: What would be the best way to implement realistic rolling friction/resistance for a circular object in Box2D?

Learn Kinematics.

Velocity += Acceleration
Position += Velocity

F = ma
So:
a = F/m
(A is acceleration, m is mass, F is net force)

Set mass to a constant if you wish, and all objects will accelerate the same.

To get net force, simply subtract friction from thrust/gravity.

Thanks. If there’s no other way to handle it using the available tools that Box2D has, I’ll look into handling it using raw physics.

AFAIK, box2D just handles collisions, not velocity physics.

Turns out Box2D does support that. Look at the website.

Edit: You should probably still learn basic kinematics anyway.

Box2D supports velocity physics, but apparently does not support rolling friction/resistance for circular objects specifically.

At least that’s the conclusion I’ve arrived at after googling and seeing some links about it:

http://www.box2d.org/forum/viewtopic.php?f=8&t=452


The force of a rolling object is actually a rotation.

So friction must oppose the rotation direction or it will instead speed up the object.

Try googling ‘friction on rotating objects’.

@HeroesGraveDev sorry, but… learn Box2D :wink:

I know exactly what problem you have, heisenbergman, I’ve been there myself (and many others have been too).
Box2D does support friction of circular objects, but you’ll see that even when setting the friction of the circle as well as the friction of the floor it rolls on to 1, it still won’t produce expected results (like a tire rolling on the road).

The problem is, that you need to fake it…
There are several options you have, all involve changing something when a contact happens. So you could for example filter the tire and the road and then make the tire move or stop, by adding additional forces tot he tire.

Or, you could use setTangentSpeed, which is another elegant solution, but the last time I checked it, my problem was, that libGDX hasn’t yet updated it’s wrapper to the newest version :frowning:

checking

Wohooow! It’s there :smiley: [url=https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/physics/box2d/Contact.java#L222]Contact.java#setTangentSpeed(float)[/url]

Seems like it was the latest commit, which made that possible. Man I love github… :slight_smile:

[quote]sluglit 13 days ago Added Box2d support for conveyers
[/quote]
Whoa, I’ll have to update my Box2D.

@matheus23: Thanks for the suggestion regarding setTangentSpeed! I’ll look into that later when I get home for sure :slight_smile:

I also got a suggestion from another forum (by the author of the iforce2d tutorials, no less), that maybe the problem was just that I was setting the damping to be too high, which is another thing I’ll also be looking at tonight.

Starting with a frictionless undulating terrain, the velocity of the ball is simple. The total energy in the system is the sum of the potential energy of the ball due to gravity, and the kinetic energy of the ball due to its forward motion. As the ball goes uphill, the kinetic energy is converted to the gravitational potential energy (but the sum stays constant), as it goes downhill the potential energy is converted back to kinetic energy.

So the speed of the ball is a simple function of the altitude of the ball. The more complex part is applying the varying impulse to the ball by the varying normals of the floor surface.

Friction simply reduces the total kinetic + potential energy, by converting some of that energy into heat and sound. As the potential energy is directly related to altitude, the loss occurs entirely on the kinetic side.