Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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 1641 times)
0 Members and 1 Guest 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: 309
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.

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

http://www.box2d.org/forum/viewtopic.php?f=8&t=452
http://www.haminthefridge.com/b_how-to-set-friction-on-circles-in-box2d/
http://stackoverflow.com/questions/11182997/in-libgdx-how-do-i-add-friction-to-a-box2d-body-object


Offline HeroesGraveDev

JGO Kernel


Medals: 309
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'.

Online matheus23

JGO Kernel


Medals: 114
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

*checking*

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

<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 »

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

Online ags1

JGO Wizard


Medals: 75
Projects: 3
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
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!