# Active ragdoll physics

**URL:** <https://forum.babylonjs.com/t/active-ragdoll-physics/49526>\
**Category:** Questions\
**Tags:** physics, ragdoll\
**Created:** [April 10, 2024, 7:10am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526 "2024-04-10T07:10:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_Anderson](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mr_anderson/32/33232_2.png) [@Mr\_Anderson](https://forum.babylonjs.com/u/Mr_Anderson)\
**Post date:** [April 10, 2024, 7:10am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/1 "2024-04-10T07:10:32Z")

</div>

Has anybody had any experience with creating active ragdolls in Babylon?

For example when you run, but a box hits you from above, the head reacts to the box while still trying to keep the animation going?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 10, 2024, 8:11am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/2 "2024-04-10T08:11:36Z")

</div>

cc @Cedric

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [April 10, 2024, 8:17am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/3 "2024-04-10T08:17:40Z")

</div>

I didn’t try but I’m curious to see how people have managed to do it 🙂

---

<div class="post-metadata">

**Author:** ![owen](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/owen/32/9325_2.png) [@owen](https://forum.babylonjs.com/u/owen)\
**Post date:** [April 28, 2024, 11:14pm UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/4 "2024-04-28T23:14:40Z")

</div>

I’m also interested in this. I found this article [http://peyman-mass.blogspot.com/2018/01/how-to-implement-active-ragdoll.html?m=1](http://peyman-mass.blogspot.com/2018/01/how-to-implement-active-ragdoll.html?m=1)

It mentions this, and I quote:

> Physically based animation is also known as active ragdoll or animation driven ragdoll and if you have used Havok animation before, it’s called powered ragdoll in Havok animation.

Which makes me wonder, now that Babylonjs can use havok as a physics engine, does this mean that we also have access to this so called “powered ragdoll”?

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 13, 2024, 9:40am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/5 "2024-05-13T09:40:19Z")

</div>

Havok wasm build doesnt contain everything possible. We cherry pick what’s needed or the wasm would be multiple Mb. Ragdoll is not used by everyone so, it’s preferable to have our own version based on user feedback.

---

<div class="post-metadata">

**Author:** ![owen](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/owen/32/9325_2.png) [@owen](https://forum.babylonjs.com/u/owen)\
**Post date:** [May 13, 2024, 11:31pm UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/6 "2024-05-13T23:31:49Z")

</div>

I see that this playground [https://playground.babylonjs.com/#DLPNQT#6](https://playground.babylonjs.com/#DLPNQT#6) has an animation group that keeps playing even after the ragdoll is turned on. I’m guessing the animation is ignored because the physics are taking precedence. Is there a way that I can extract the current animation frame values for each bone and convert them to the appropriate physics force in order to blend the ragdoll back into the animation shape over time?

In playing around in the js console I see I can get what frame the animation is on using:

```auto
scene.animationGroups[0].animatables[30].masterFrame

```

But I haven’t figured out how to see what value the frame is supposed to be at.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 14, 2024, 8:53am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/7 "2024-05-14T08:53:50Z")

</div>

Once you have a frame number, you can get the value of an animation by calling `Animation.evaluate(frame)`. For a given animation group, you can get the list of all animations by calling `AnimationGroup.targetedAnimations`.

---

<div class="post-metadata">

**Author:** ![owen](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/owen/32/9325_2.png) [@owen](https://forum.babylonjs.com/u/owen)\
**Post date:** [May 25, 2024, 2:09am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/8 "2024-05-25T02:09:08Z")

</div>

LOL looks like a zombie trying to stand up…

[https://playground.babylonjs.com/#DLPNQT#12](https://playground.babylonjs.com/#DLPNQT#12)

first click on “Ragdoll on”, then click on “Impulse” to see my attempt at making active ragdoll.

My thinking here was:

1. There are 69 bones in the skeleton
2. There are 13 physics bodies in the ragdoll (so right away there is a mismatch between the ragdoll parts and the skeleton animation… but let’s try anyway!)
3. As the animation plays get the frame number, loop through each of the physics bodies, find a corresponding bone and get its supposed animation value at that time frame. Calculate the difference between the animation target value and the ragdoll transform node value and apply a small impulse to drive the transformNode/physicsBody in the direction of the animation.

Based on the console logs though, the target animation values and the ragdoll transformNode values don’t seem to be in the same coordinate space. Even before ragdoll is turned on, these two values are very different. So I think the impulse applied is pretty non-sensical. I’m not sure. I’m out of my depth here.

Any ideas?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 27, 2024, 3:08pm UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/9 "2024-05-27T15:08:42Z")

</div>

Assigned @Cedric on May 27, 2024, 3:08pm UTC



---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 28, 2024, 8:12am UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/10 "2024-05-28T08:12:36Z")

</div>

> [@owen](#):
>
> So I think the impulse applied is pretty non-sensical. I’m not sure. I’m out of my depth here.

Angular impulse takes a vector (a torque force) and not Euler angles

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 6, 2024, 2:59pm UTC](https://forum.babylonjs.com/t/active-ragdoll-physics/49526/11 "2024-06-06T14:59:25Z")

</div>

Unassigned @Cedric on June 6, 2024, 2:59pm UTC


