physicsBody: angularDamping/linearDamping question

Hi community,
I’m currently experimenting with two bodies connected via a distance joint and I’m wondering if the joint’s connection has something similar like anagularDamping/linearDamping of physicsBody.
Thanks in advance,

Ping @Cedric to see if he has any ideas ?

I checked the constraints doc and didn’t find anything related to damping. Maybe you can simulate that with heavier attached objects.

Thanks for the replies!
@Cedric: Good idea, I’ll give it a try.

Hi guys. In Cannon, located natively on mesh.physicsImpostor.physicsBody… there IS .linearDamping and .angularDamping. See lines 62 and 63. EITHER will work for a damping system for the box, because it has both linear and angular movement as it hinge-spins around it’s cylinder buddy.

BUT… this is not what you seek. You seek an angular damping on the hinge joint itself. I went deep-diving into Cannon’s joints… looking for things… and found nothing… except… using a setMotor(speed, maxForce)… where speed (neg or poz value) is mostly for setting (counter-) spin direction, and maxForce sets the amount of allowed “backspin”… which is very important for brakes. We don’t want them to stop immediately. We want them to “frictionize” the hinge until spin comes to a gentle stop.

SetMotor worked… but… I couldn’t determine WHEN the motor’s counter-force… stopped the hinge from spinning. And so, I couldn’t tell WHEN to shut-off the motor… and thus… after stopping the spin… it started slowly spinning in the opposite direction. Erf. Using an opposite-direction-running WEAK maxForce motor… to dampen the spin… works… but it comes with hassles.

Although damping methods like lines 62/63… are working… they are actually damping the impostor, and NOT the hinge pivot axis. So they are “cheating”… and not what Holger is asking-for. Oh well… sorry.

Umm… this playground just spins-up the hinge… and then 3 seconds later… applies the brakes, and switches the background color. It works pretty good, I guess. LinearDamping seems more powerful than angular, in this demo. Damping values of .9999 etc… really slams-on the brakes (adds much resistance). .3 and below… hardly noticeable.

Sorry for the messy playground. Holger/others… if ya got questions/comments about it… just holler… I don’t mind yapping. :slight_smile: I’m not sure if this method will work in Oimo or Ammo physics engines… maybe. Probably not. :slight_smile: Party on.

1 Like

Hi Wingnut, many thanks for the effort :smiley:
Indeed, setting liniearDamping to 0.9 made the system feel more stable now, even when two bodies connected via distance joint. I’m new to Babylon JS so there is so much to learn…
What I’m currently working on is something what will eventually become a game (if I am able to put enough effort into it). It’s basically a mixture of the games Virus (Amiga) and Thrust (C64) which I loved playing ages ago. This combines the navigation/steering from Virus and the physics of Thust (mass connected via distance joint). Thanks again for the help!

1 Like

My pleasure, Holger. You sound like someone in MY age-group or nearby (I’m 61). I, too, was a C-64 and Amiga nut, but I don’t remember those named games (I think I have a case of memorhoids). :slight_smile:

Since you are playing with physics, I’ll tell you another damping-related secret… mainly involving spheres. Soon, if not already, you will notice that friction… doesn’t seem to work on sphereImpostors.

A little physics thought tells us why. Not enough ground->sphere surface contact.

When I first encountered the issue, I wasn’t smart enough to figure it out on my own, and @fenomas and @RaananW had to rescue me from Dummyville Prison. :smiley: (Jailbreak plan designed by professional native-lands guide… @Raggar)

I think all of them… taught me the same cool fix…


Put it on the renderLoop or other periodic loop. (lower values = more friction/damping). A “hot coder” would STOP calling it… when physicsImpostor.physicsBody.isSleeping = true. (after setting all needed native sleep properties)

I call it “Raanan’s Leather Boot”… cuz… it’s like pushing a work-boot against the sphere… to slow its roll over time. :slight_smile: The above example reduces sphere rolling by 5% every time it is called. It works on a BJS level (not needing to access any “native” properties or methods on physicsBody)… so we can count-on the .scale() function being available. If we would need to “reach-down” further to physicsImpostor.physicsBody… then we have entered “native” land.

In Cannon’s case, physicsBody is a Cannon object, not a BJS object (I think). SO… if we receive a Cannon vec3 when we asked-for a get angular velocity… THAT type of vec3 might not have a scale() helper-tool on it. It would be a different version of vector3… than the BJS version. With me?

Same with rotation-Quaternions (physics engines hate .rotation Eulers, and much-prefer .rotationQuaternion-type of rotations). If we get a rot-Quat from mesh.physicsImpostor… it will be a BJS Quat-type. If we reach further toward native-land and get, for example… Oimo’s rigidBody… mesh.physicsImpostor.physicsBody.quaternion… then the return value will be a OIMO-type Quat… and will not necessarily be interchangeable with a BJS-type Quat.

In general, when we reach beyond physicsImpostor… down into physicsBody land… we could get a handful of alien lifeforms and datatypes. :slight_smile: Reaching into native-land is fun and encouraged… but we must follow the rules of the physics engine… when we play down there (more docs to read, yay).

And then, or course, all the physics engines do things differently from one another, so, “going native” is a new experience for EACH brand of physics engine. FUN! :slight_smile: Ok, bye again… sorry for the rattling.

Hi Wingnut, thanks for the thorough explanation, much appreciated :smiley: … and yeah, I’m not that young either, heading straight towards 50 :grinning:
I must admit that I’m quite scared when it comes to vectors, matrices, quaternions and math in general. I’m sure that I’m going to need further help on all those topics when I’m digging deeper into BJS.
Cheers :slight_smile:

:slight_smile: Don’t worry… BabylonJS has all the toys needed… to avoid difficult programming. Often, the most difficult part… is terminology… which is needed for searches. A little greasy math in physics, but other than that, it’s all fun and there’s not much need for heavy math, ever.

Check out Necip’s “Cool Hidden Examples” thread… it’s just packed with people doing “holy crap” playgrounds… with very little code/math. Just a HUGE pile of toys. :slight_smile: Same with the main website demos area. Yum!

One of my faves… Character Study - Babylon.js - Samuel Girardin - - Locate the tiny x30 button and get 30 raggies out there. Now start your favorite song on a nearby player… and then click the “F” button to the beat of the song. TOO FUN! (drool)

Also, use the arrows on the "G"ravity button, to float the pile of raggies far into the sky, then go back to G -9 to slam them into the ground. You’ll see that some of their body parts get stuck in the ground. Now try to float them with positive gravity again… FUNNY! Tap that F button to the beat of your song… then, too. Don’t forget to mousewheel in/out, sometimes, and pan-around. MINUTES of demented fun, I tell ya. :smiley:

Yes, already discovered…loads of good stuff there to learn from :slight_smile:

1 Like