Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Box2D] Best way to implement rolling friction/resistance?  (Read 2394 times)
0 Members and 2 Guests are viewing this topic.
Offline 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?

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

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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.

Offline 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:

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

Offline 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 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 Sad


Wohooow! It's there Cheesy

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

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

JGO Coder

Medals: 14

L___ o_ G___ a__ P___

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

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 Smiley

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.

Offline ags1

JGO Kernel

Medals: 120
Projects: 4
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.

Riven (28 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (27 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (25 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39

Jesse (39 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!