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 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.
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:
It maps the joints to the bone names in the character’s hierarchy. So every frame, the transforms can be copied across (in
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.
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.
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!
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?
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.
Is it strange that I can watch my falling ragdoll for hours?
Sometimes I wonder if he’s drunk or dead…
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.