Small lib for creating ragdolls

Hi everyone. I made a small javascript class to help with the creation of ragdolls. Here it is on github.

I made some examples on the playground:

In theory it works with AmmoJS, CannonJS and OimoJS… however, I only got it to work relatively well with OimoJS, mainly due to the joint limits that are available on some of the OimoJS joints.

I made this for a personal project I’m currently working on, and then decided to open source it. Hope it helps someone out. Any feedback is much appreciated.

22 Likes

This is super cool! Thanks a lot

1 Like

I am looking for similar feature, thank you very much! :smiley:

1 Like

Hello Necips! We can totally choose rotation directions with this lib. If the bone is rotating in a way that seems unrealistic, we can choose other rotation axes. In the examples I posted above, this is the ‘rotationAxis’ property in the config. We can also define rotation limits, with the ‘min’ and ‘max’ properties. But yes, the examples I gave could be more realistic (they were made in a hurry :cry:).

Now, rotation limits aren’t available for all the joints, and as far as I know, they’re only currently available if we choose OimoJS as a physics engine. However, I believe we can achieve something similar to rotation limits using other physics engines and/or joints. It’s probably gonna be a little bit tricky… but there are some tricks I believe could work, such as:

  1. Having some sort of callback after each physics step (something like the afterStep we see in the PhysicsImpostor Class) and reseting the rotation values if they go above a certain limit. I actually tried this, but failed miserably. But only because I’m super lazy… but hey, if there’s anyone out who really needs this, I can try it again :grin:.
  2. Another idea would be using some kind of stopper meshes. Wingnut talks about this method in some posts, like this one.

Another super valid criticism of this lib would be: well, if we’re using hinge joints (as in the examples I posted), we can only rotate in 1 axis… and there are clearly joints in our body that rotate in more than 1 direction (e.g. shoulder joint and knee joint). What if we want a joint that rotates in multiple directions AND has rotation limits like I described above?? For this issue, there are also some possible solutions:

  1. We can choose another joint that supports rotation in multiple directions (e.g. ball and socket joint), and use the rotation limit method I described above (using the afterStep in the PhysicsImpostor Class and adjusting angles when needed).
  2. Another solution would be using 2 or 3 hinge joints between bones (instead of just the usual 1 joint), and make each hinge joint rotate in different directions. Hinge joints already allow rotation limits (with OimoJS), so we’re good.

Ranaan talked about the afterStep physics solution and the multiple joints between bones solutions in this post.

nice!

1 Like

Think that is a little better https://playground.babylonjs.com/#40AH5S#5 then Babylon.js Playground. :slightly_smiling_face:

1 Like

Looking good!! I thought having overlapping collider boxes would cause issues, but apparently not :stuck_out_tongue:

1 Like

May we should use bigger boxes?

Buahahah that’s hilarious :joy:

@REX_DUNGEUR we most definitely can. I played around a little bit with the Vita model and added slightly bigger boxes (and some angle limits as well)

https://playground.babylonjs.com/#40AH5S#9

We can see that there is less intersection of arms/legs happening, which is nice. Also the mesh is less likely to go bellow the floor. Is it the best approach for all cases? I’m not sure :stuck_out_tongue:

1 Like

lol @Necips:joy:.Look at that:

I’m working… :slightly_smiling_face:

Here @Necips: https://playground.babylonjs.com/#PVKQM1#3

1 Like

Or that: https://playground.babylonjs.com/#PVKQM1#4



Cool!

Huuh! What on earth is that @Necips …? :face_with_raised_eyebrow:

Sorry about resurrecting the thread, but I’m curious if anyone has any idea how to gracefully return the character from the ragdoll to an animated player character? Like having some animation of the character getting up from the ground, but gracefully since the limbs are pointing to every possible direction?

I think this has been done in game development for other platforms, anyone has an idea how to implement this? Like generally speaking :smiley:

Update for Havok: https://playground.babylonjs.com/#U6ELFW#3

Code needs some love. I have just added the Havok replacements and some workarounds; see bottom in particular. Also, one lazy thing to note: I used a HingeConstraint for all body parts.

6 Likes

Sorry about resurrecting the thread, but I am trying to do make this guy have a cloth around (like a shirt or something )
https://playground.babylonjs.com/#BCU1XR#1616
for starters maybe a rob around the shoulder.
I think this playground will also help https://playground.babylonjs.com/#RJ09NP#2.
What I want to do is have a shirt around and it behave like an actual shirt , so if the player moves it should also, if gravity is inversed around certain point let’s say the shoulder part the shirt is fixed but when the player is doing a hand stand kind of pose the shirt comes down , just like an actual shirt.
Can anyone please help me with this?
Something like this https://youtu.be/KBfxnayIlOY?si=yi8Lhoy8CsXVttQl

Hope this link helps

1 Like

Sorry to ask, But I am kind of new to BabyonJs , Can you help me what concept is there in these demos and how it can help my problem?
I am seeing this for the first link


and for the second link