[SOLVED] How to make a ragdoll?

I don’t need it right now, but I would like to know how to make a ragdoll, so that the player can lift a body in my game. Anyone have experience with that? I already have characters with bones and animations.

I haven’t seen an example of an animated character being turned into a ragdoll in PlayCanvas yet :thinking: There is a ragdoll example by Will that can be seen here: https://playcanvas.com/project/431888/overview/ragdoll

But that example assumes that all the body parts are separate entities though.

My character does not consist of physically separate entities, but I know that I can access the entities by script. Perhaps I can also add the necessary components by script.

I am on mobile right now and unfortunately the editor is not yet optimized for mobile so I will study the example project when I am at home.

Yes, that’s exactly how I did it. I create a set of entities that represents the ragdoll bodies connected by joint constraints. And there’s a script which, every frame, copies the body transforms into the transforms of the character’s hierarchy.

That project is quite cool, but I never quite got it working 100% right. The joints aren’t oriented correctly in places. It’s definitely fixable. I just never go around to it. :smile:

1 Like

Hi @will, I tried to replace the model for my own model, only then the result is a bit different. I think the arms and legs are stretched too much and the body is also twisted.

Could you please explain a little bit about the different scripts so I know where to make adjustments?

I think you have to align the joints with the bone transforms they are supposed to drive.

So yeah, if your character is a different size, you need to reposition the joints/bodies.

The only script you should need to edit is this one:

https://playcanvas.com/editor/code/431888?tabs=5390445

It maps the joints to the bone names in the character’s hierarchy. So every frame, the transforms can be copied across (in Ragdoll.prototype.update).

As I said before though, there are still bugs related to joint orientation and limits that I never figured out. So anyone that does figure that out, you’re smarter than I am. :smile:

Yes, I already did that. I also change the entitites names in the ragdoll script.
Maybe I can take over all rotations by script to.

https://launch.playcanvas.com/916360?debug=true

LOL, that looks so painful.

The key to solving the problems there are understanding the connections of the joints in the joint hierarchy, and how the joints are oriented.

Painful to see indeed, in several ways! :sweat_smile: :yum:

Can you give a little explanation about constraints.js and hammer.min.js?

hammer.min.js is just used to touch controls. I think that project is a fork of a very old, early revision of the model viewer start kit which used to use hammer.js.

constraints.js exposes 3 different constraint types from ammo.js. It’s fairly straightforward.

It is a lot of better already, but I think there is still something not in place. Can you see what that is?

https://launch.playcanvas.com/916360?debug=true

2 Likes

Great work! Looks like the rotations or the joint orientation need tweaking/changing so that they bend in the right direction. Like Will, I never quite got it right without a lot of trial and error.

Thank you all. I think this is the best I can get. Now let’s see how I can implement it in my game.

Nice job, @albertos!! Looks pretty good. I would love to revisit this sometime and make it easier for people to recreate. It is slightly tricky to set up at the moment.

1 Like

Is it strange that I can watch my falling ragdoll for hours?
Sometimes I wonder if he’s drunk or dead…

1 Like

Can I move one part of the ragdoll (for example changing position by script) so that the other parts follow automatically (because they are connected)?

Well, if you used teleport on one of the rigid body components in the ragdoll hierarchy, the joint connection to the other body would be instantaneously stretched and attempt to snap back to restore the original distance. The larger the distance, the more likely the simulation will ‘explode’.

Aha okay, thanks for your explanation. Then I have to think of another way.