How would my pawn go Ragdoll and then back to animations?
Is there a way to make a pawn go ragdoll, fall to the floor for a few seconds, and then play an animation of the pawn getting back up and continuing to work normally?
To turn to ragdoll, you just have to enable physics simulation.
// enable physics for all default bodies. // if you have fixed bodies, you'll have to call SetAllBodiesSimulate to unfix all of them
// now wake up all rigid bodies.
But also you have to disable Pawn's movement/inputs so that they can't move their mesh.
If you'd like to go back, you'll have to do this in reverse.
You'd like to put sleep on rigid body, so it doesn't move anymore.
But also you'd like to disable Simulate, but enable blend so that you don't simulate anymore, but you'd like to blend from physics position over time.
You can call this function to set how much weight you'd like.
Ideally over time, you'd like physics weight to be 1->0 over duration of the time.
You can do all this in blueprint.
Thank you very much, Lina! I managed to do it with your instructions. Here's my approach through Blueprint.
So I set out to make it so that if the player holds F he will turn into a ragdoll and if the player releases the key, the character will stand up with physics blending. For starters, I disabled input for the Player Controller (you'd probably want to actually grab the Character's Controller rather than 'Player 0' like I did here) then I turned on physics for the Capsule Component because I was lazy and didn't want to find a way of disabling it without the character falling through the ground. If I were doing this for reals I'd probably scale down the capsule component while the player is a ragdoll or something along those lines so that it doesn't inhibit the normal physics of the ragdoll.
Note: Your Capsule Component must be set to a 'Custom' physics option. To do this, set the capsule component's collision preset to 'Ragdoll' then change it to 'Custom'. From there, you're going to want to check the "Ignore PhysicsBody" check box so that the capsule doesn't infinitely collide with the ragdolled mesh or fall through the floor.
Note 2: The blue man skeletal mesh doesn't come with a physics asset. You must right click the skeletal mesh in the content browser and generate one. You must also set the collision preset of the mesh component to 'Ragdoll' in the character blueprint.
Next, instead of simulating physics directly like Lina suggested, I chose to "Set All Bodies Below to Simulate Physics" for all bones below bone index 1. (the pelvis) This way, the root stays attached to the Capsule Component and the two do not become detached. (which otherwise ends up with very strange results) Now if you were to test this out, when you press F your character will turn into a ragdoll. Make sure you jump forward or something first, as the Capsule Component can stand on it's own and your character will kinda just start dangling in mid-air otherwise. This is why I think it would probably be a good idea to scale down the Capsule Component when the character actually ragdollizes.
Next was getting the character to stand back up with blending.
Upon releasing the F key, physics are no longer simulated on the Capsule Component, Move Input is re-enabled, and Actor rotation is set to (0,0,0) to undo any rolling the Capsule probably did. You can ignore the "Set Enable Physics Blending" node, as well as the next "Set All Bodies Below Simulate Physics" nodes, as they are actually unnecessary. It's important to note that physics must still be simulated in order for physics blending to work, which is probably the only problem in Lina's tutorial (This could just be a Blueprint thing though), so make sure that you don't "Set All Bodies Below Simulate Physics" to false until you're done blending the mesh back to 0.0, which we're about to do.
By this point your character will stand up again, but he will still dangle in mid-air and it generally looks hilarious as you run around like this.
Finally you're going to "Set All Bodies Below Physics Blend Weight" to a custom float variable with a default value of 1.0. As Lina mentioned, you're going to want to gradient this value down to 0.0 so that the character slowly goes back to his normal animations. You can do this by setting up a timer to subtract 0.1 from the blend weight every certain number of second or any other way you'd have a value change over time. To make it a bit more polished you could have a getting up animation start to play right before you start doing the blending, and you'd get an Unreal 3 feign death type look from that.
And that's my pretty rough way of getting this to work with Blueprint! I'm sure there are several areas that can be improved, such as what to do with that clunky Capsule Component, but I bet you can figure out where to improve on it on your own. Like I said, my first guess would be to shrink the capsule component down while they're a ragdoll and scale it back up when they stand, but that could have problems all its own.
To further complicate things, none of the ragdolling is replicated, so that's something else we still gotta figure out.
Thank you so much for the feedback. This is very helpful.
I expected it's going to have some hurdles because this hasn't been tested well but I'm glad to hear you managed to make it work.
Could you not just disable collision of capsule when you go ragdoll? And enable collision again when you're out of ragdoll?
I think this was smart move. I think the key is though you'd like to make sure root doesn't have weight and on the ground. Like other mesh often imported root as pelvis or hip.
When I get to this, I'll look into this again. My intention is not simulate, but it seems there is code blocking blending with physics when not simulating. Thanks for the tip.
We have a rough plan to work on this, not necessarily just ragdoll, but physics object replication. Ideally it would be great if you don't have to, so it would look seamless in every machine although they all see different simulation.
answered May 06 '14 at 06:43 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here