Jump to content

How to create good friction ?


Recommended Posts

Hi guys!  Welcome to the forum, LiquidSebbey!


  There might be another way, but it is SUCH a ridiculous demented way, that maybe I shouldn't say it.


Raanan was recently able to get Oimo heightMap/displaceMap physics activated (thx R!)... and thus you can set the roughness of the ground plane (go high subdivs).


It would likely require "generating" a 2D image buffer (a dynamic texture)... maybe setting alternating colors per pixel.  Maybe a pattern like #000, then #111, then #000, then #111, staggering each row of pixels so that there is never a #000 adjacent to a #111.  In other words, black, dark gray, black, dark gray, etc.  Once the texture is complete, use it as a physics-active heightMap.  This will give SOME resistance to sphere roll, I would think.


But... it also might make the sphere vibrate a bit as it rolls.  And it also might not work at all.  AND, it would need to be a very high resolution ground plane... lots of subdivs.


This idea is probably implausible, and certainly far more complicated than Fenomas' idea/solve.  But, I thought I'd mention it, and see if anyone wanted to do some experimenting or commenting.  Be well, guys!

Link to comment
Share on other sites

Hey people,


I really liked the "air friction" idea. I actually thought the physics engine do that internally, but I never tested. What a surprise...


So, here is my suggestion - http://www.babylonjs-playground.com/#OJVVA. This is very prototypical, and should be improved. a LOT. but, it is working :)


@Wingnut, my first idea was also a heightmap. something rough, like a grass texture that will keep friction always working. but that would require a lot of computation (i can only assume). I will give it a try thou, I think it might be a nicer solution.

Link to comment
Share on other sites

Thanks wingnut for welcoming me to the forum :)


..-> Isn't there another way of smoothly stopping those candies from rolling as a alternative way? The air-way seems legit, but not supported by oimo and the height map seems to take a lot of unnecessary resources/computation.

You are right. but oimo/cannon would probably calculate it the same as what I was doing in the first example (I can only guess). Dividing 3 number * numberOfBalls each frame should not cost too much CPU time, and, if it works, why not use it... It is a simple hack. I didn't dive into the engine's code to check if and how they do it, but it seems like they ignore friction when a constant connection has occurred.

Link to comment
Share on other sites

Yep, they seem like they never settle.... interesting :-)

This are all just experiments, we are learning with you.

Something I wrote on my last post made me wonder - the friction is used with every contact, but not with every constant contact. So, technically, if we have a lot of boxes, small ones, that will created a single visible ground, the friction will be calculated with each transfer between boxes.


Careful, very slow, as it created 30*30 ground boxes. But, it works... Now it should be optimized for your needs :) .

I still like the first implementation - check if the balls have a velocity, divide it in a constant each frame, and you got yourself "air friction".

Link to comment
Share on other sites

(tap tap) Is this thing on?


Folks, ground friction does not slow down a rolling (ideal) sphere! If you find a way to make it do so, I think it's a bug in the physics engine. ;)


Reason: typical physics engines only model sliding friction - the friction of one surface sliding along another. When a sphere is rolling, it's like a car tire with good traction - the sphere's surface and the ground are not sliding relative to each another. The only friction that applies then is rolling friction, which comes from factors most engines don't model (molecular forces, imperfect surfaces, etc).


So unless someone implements rolling friction in oimo, air friction is really the answer here. Air friction force is proportional to velocity, so the easiest approach is to just apply a force to every body, equal to its velocity times some small negative constant.

Link to comment
Share on other sites


So unless someone implements rolling friction in oimo, air friction is really the answer here. Air friction force is proportional to velocity, so the easiest approach is to just apply a force to every body, equal to its velocity times some small negative constant.

yep, I agree with you (no reason to speak so loud :-) )

This is why this solution (very prototypical) will work wonderfully (cannon.js code):

var factor = 1.01;scene.registerBeforeRender(function () {  meshesBodies.forEach(function ( {    b.velocity.x /= factor;     b.velocity.y  /= factor;     b.velocity.z  /= factor;   });});

This simplifies the entire process, and might not be 100% correct. But, then again, so does thinking all physics-bodies are spheres or boxes...

Link to comment
Share on other sites

:)  What's the issue, Fenomas?  The bumpy ground test doesn't use friction whatsoever, and doesn't claim to.  When I suggested rigidBody.sleepThreshold... I was speaking about the continuous movement seen on the bumpy ground demo.


Let it be known that we all hear you when you teach us about sphere ground friction... and so far, it seems we all agree with you.  (and thanks!) 


That doesn't mean we're going to quit trying methods to fake it, though.  :D

Link to comment
Share on other sites

  • 1 month later...



I don't mean to revive an old thread, but!


Cannon.js has this feature integrated already. It is called linear damping. You can see how to use it here - http://www.babylonjs-playground.com/#OJVVA#5 , line 30. This will create a certain "friction". Setting this to "0" will create no constant friction. angularDamping does the same for rotation.


Hope this will help someone :)

Link to comment
Share on other sites

  • 1 year later...


(fresh playground)  :)


(linearDamping & angularDamping, halfway down the parameters list)


For Oimo... hmm.  You can do the "Raanan's Leather Boot" maneuver.  He rubs his big fat work-boot... against the rolling mesh... like this...

scene.beforeRender=()=>{ sphere.physicsImpostor.physicsBody.linearVelocity.XXXXX(.95) }    // .05 'bootons' of linearDamping  :)

I don't understand the "syntax" of the two "scale" things allowed for Oimo Vec3 class objects.  But here's what Wingy's bad Oimo api says...

public function scale(v:Vec3, s:Number):Vec3 {


public function scaleEqual(s:Number):Vec3 {

If i were to guess, I would say ...   set XXXXX to scaleEqual.

End result:  scene.beforeRender=()=>{ sphere.physicsImpostor.physicsBody.linearVelocity.scaleEqual(.95) }  (no promises, just speculation)

Raanan's  Leather Boot - "Oimo sphere brakes that YOU can count-on!"  (guess)  :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...