Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (603) Games in Android Showcase (171) games submitted by our members Games in WIP (652) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 [Box2D] Best way to implement rolling friction/resistance?  (Read 2407 times) 0 Members and 1 Guest are viewing this topic.
heisenbergman

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

 « Posted 2013-05-27 03:27:05 »

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?

HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #1 - Posted 2013-05-27 05:47:48 »

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.

heisenbergman

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

 « Reply #2 - Posted 2013-05-27 06:53:42 »

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.

HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #3 - Posted 2013-05-27 07:18:49 »

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.

heisenbergman

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

 « Reply #4 - Posted 2013-05-27 07:32:18 »

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
http://www.haminthefridge.com/b_how-to-set-friction-on-circles-in-box2d/

HeroesGraveDev

JGO Kernel

Medals: 360
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #5 - Posted 2013-05-27 07:58:20 »

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'.

matheus23

JGO Kernel

Medals: 122
Projects: 3

You think about my Avatar right now!

 « Reply #6 - Posted 2013-05-27 08:16:40 »

@HeroesGraveDev sorry, but... learn Box2D

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

*checking*

Wohooow! It's there Contact.java#setTangentSpeed(float)

<edit>Seems like it was the latest commit, which made that possible. Man I love github... </edit>

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
heisenbergman

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

 « Reply #7 - Posted 2013-05-27 08:29:33 »

Quote
sluglit 13 days ago Added Box2d support for conveyers
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

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.

ags1

JGO Kernel

Medals: 124
Projects: 5
Exp: 5 years

Make code not war!

 « Reply #8 - Posted 2013-05-27 09:27:46 »

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.

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 SHC (11 views) 2015-08-01 03:58:20 Jesse (17 views) 2015-07-29 04:35:27 Riven (38 views) 2015-07-27 16:38:00 Riven (19 views) 2015-07-27 15:35:20 Riven (22 views) 2015-07-27 12:26:13 Riven (12 views) 2015-07-27 12:23:39 BurntPizza (32 views) 2015-07-25 00:14:37 BurntPizza (44 views) 2015-07-24 22:06:39 BurntPizza (25 views) 2015-07-24 06:06:53 NoxInc (32 views) 2015-07-22 22:16:53
 theagentd 51x wessles 45x basil_ 35x KaiHH 26x orangepascal 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x Jesse 11x princec 11x CelestialCreator 11x klaus 11x Zaneris 9x philfrei 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org