Apply gravity to mesh

Hello guys !
I’m new to 3D and babylon.js, so sorry if the question seems stupid :slight_smile:

I’m trying to import some character in my scene, and apply gravity to it, so that it falls to the ground. I’m able to apply gravity to a sphere, which proves the plugin is being used properly, but the character seems not to be affected by the laws of gravity.

You can find a sample here: https://playground.babylonjs.com/#BCU1XR#830.

Checking at imported meshes in the callback (“newMeshes”), I can see there is another mesh I didn’t use while creating my character; should I use it?

Thanks in advance!

Hiya RR, welcome to the forum.

https://playground.babylonjs.com/#BCU1XR#833

Sort-of working. There’s two main mesh involved here… yBot and unit. I activated a showBoundingBox on unit, and changed to arcRotateCam… just cuz I like them. :slight_smile:

Line 44 was giving me a console warning about adding a physicsImpostor to a mesh with a parent (unit)… so I removed unit.parent in line 42.

I needed to do that “un-parenting” so that lines 52-55 would work. Those lines… wait til after scene start, then 4 more seconds, and then fires upward physics thrust (impulse) at the center of unit. (line 54). As you can see, we get a little physics “hop”, so basic boxImpostor physics is working.

Oh yeah, I DID change from planeImpostor, to boxImpostor (on unit). Also added some mass, for unit. I also turned-off all animations. An idle animation (standing around, arms down)… is indeed an animation… and if it is running… it might override physics. I wanted all animation off, so I could do a physics impulse test… and make sure gravity was working.

Even more tweaking: https://playground.babylonjs.com/#BCU1XR#834… lights, unit rotation and up-scaling, camera tweaks, impulse direction tweaks, goofin’ around. Sometimes it tips over backwards, sometimes not. hmm.

That seems to do it. Thanks!

1 Like

My pleasure. I bet you sort-of wish that the yBot would automatically go “ragdoll-ready”… with tendon-limited physics joints like human joints are, and separate physics impostors for each major bone of the armature.

You know… ready to fall from a Ferris wheel… flailing brutally off-of the iron cross-members… landing with a leg behind the head and another up the butt. Dynamic Assessment RagDoll Tutorial | benfavaloro

It’s much more interesting than a single box impostor, eh? I agree. I’m hoping someday… we can have a “snap-on” quick-add physics-ready ragdoll armature, but it would be difficult to “universalize” that armature (so it works on ANY skeleton).

To be frank, I don’t know where the future of snap-on ragdoll physics will go. One would suspect… that most of the world wants it to become much easier to do.

Oimo.js Ragdoll There’s the OimoJS ragdoll, and we have OimoJS plugin, along with CannonJS and AmmoJS/Bullet. I dunno how much you know about physics joints, but, you are allowed to use collision masks, filters and groups… to determine WHICH impostors are allowed to collide… with which others.

To hurry-along my point, the Oimo ragdolls are rather “stiff” because they did NOT turn-off collisions between impostors on each end of the joints. They put very little joint-gap between the shapes, and it is THAT… that causes Oimo rags to be stiff. Their hinge joints won’t flex very far… due to shape collisions. There is a button to turn-off the collisions. Give it a try. The joints bend much further and the dolls are less stiff. I’m not sure what type of joint limiters go-active… when collisions are set OFF… but there appears to be SOME joint limits that go active. Someday I’ll study it… maybe.

The best ragdoll I have seen so far, with BJS… is Sam Girardin’s “Old Man”… Character Study - Babylon.js - Samuel Girardin - It won’t take long to learn about the good and bad of ragdolls and hard-animations… after you push a few hundred buttons on Sam’s “lab”. I like pushing the x10 button and then repeatedly tapping the “F” button… to the beat of a cool song… such as Diner. :slight_smile: TOO FUNNY!

Generally speaking, when animating… only crude box physics surrounding entire body - allowed. When gravity on and full boney-physics and joints/limits active (ragdoll mode), animating is nearly impossible unless done by applying physics forces. Keyframe animations and physics-active skeletal ragdolling… don’t get along. One movement boss, or the other, but rarely/never both movement-bosses used at same time. Sammy’s “old man” ragdoll makes this reasonably clear. Either you are animating (walking, running, standing-idle, etc)… or you turn on gravity and go ragdoll mode. Doing both at same time… probably near impossible.

Just my opinions… feeble knowledge levels, etc. I’m probably a solid 40% wrong but, maybe not. :slight_smile:

Sam’s “Old Man” ragdoll armature “lab” thing… is older. I think it uses BJS 1.10 or 1.14. And, I think I have a complete archive of it: http://urbanproductions.com/wingy/babylon/oldman/Oldman_onefile.zip I think @Raggar did a little work trying to make it into a playground… let’s see if he has any comments about that.

AmmoJS has rope impostors! Although they are still performance-piggy unless you drive a Cray, they COULD signal a future of using invisible puppet strings to control a ragdoll. :open_mouth:

bone.physicsImpostor.applyImpulse(directionWithMagnitude, whereUponTheImpostor) is probably lots easier and does the same. But, can you imagine how many little physics applyImpulses are needed to cause a ragdoll to stand-up straight and walk, with proper arm-swing and leg motion? Probably a few hundred impulsings per second… at all sorts of locations, directions, and magnitudes. erf.

But a true walking ragdoll, moved only with physics forces and not with keyframes… would be SWEET, huh? Continuous up-impulse on both shoulders… to keep body from collapsing to floor. Same on top of head, to keep head from tipping over. (Sam’s Old Man is hung by/from his head.) Then… try to get natural walking leg movement, using TONS of little applyImpulses per step. HARD, I bet.

@Wingnut
Something changed in the engine, so the PG version no longer works. Might be simple to fix, though. Haven’t had a look at it.

I just wanted to apply gravity to my mesh, I didn’t think about ragdoll stuff :smile:
The main objective was to spawn a guy on a map at point A, and then make him go to point B while respecting the ground relief, but maybe gravity is not needed for this case; I think I’ll wait for the 4.1 release to use the navmeshes system :grinning:

1 Like

Have you considered using the native collision system?

If you dont need a physics engine, you can use babylon’s collisions, if you define ellipsoids correctly. a quick example:

https://playground.babylonjs.com/#BCU1XR#846

and documentation:

https://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity

I plan to use a non-flat ground, so I’m scared of the result, but I’ll give it a try, thanks :slight_smile: