Animated pawn to go ragdoll and back to animations

Hi all

I’m trying to set my character to ragdoll and then get back up. The first part seems to work just fine, but the latter has major issues.

Setting the ragdoll is done like follows and it works fine:

        RagdollBlendOut = 1.f; // Variable to track blending out from ragdoll
        GetPawnMesh()->SetAllBodiesBelowSimulatePhysics(FName("root"), true);
        GetPawnMesh()->SetCollisionProfileName(FName("Ragdoll"));

Getting back into animated mesh I have following code in place. First I put the rigid bodies to sleep:

        GetPawnMesh()->PutAllRigidBodiesToSleep();

then I do in tick function the following blending:

        RagdollBlendOut -= DeltaSeconds / RagdollBlendOutDelay;

        if (RagdollBlendOut <= 0.f) // Blended out completely
        {
            RagdollBlendOut = 0.f;
            GetPawnMesh()->SetAllBodiesBelowSimulatePhysics(FName("root"), false);
            GetPawnMesh()->SetCollisionProfileName(FName("CharacterMesh"));
        }
        else // Still blending
        {
            GetPawnMesh()->SetAllBodiesBelowPhysicsBlendWeight(FName("root"), RagdollBlendOut, true);
        }

The problem is that when it’s blending back from ragdoll, the character starts to move/spin wildly. And wildly in here means that it can even end into 100m into the sky, or even outside of skybox. I have noticed that the longer the blending in time is, the more wildly it flies away. The blending time doesn’t affect otherwise than how far it will end up. The motion is just as violent. If I just end the simulation without blending, the mesh ends up under/side of the capsule component, upside down or partially sideways. The mesh also stops following the capsule component after this. I can see all animations playing on the mesh when the capsule component moves, but its not following the capsule anymore.

Any idea what could be wrong and/or what to try out? I can provide further information on my implementation if that helps resolving the issue. I tried also similar approach than explained here [link text][1], but the same spin/move problem persists.

The skeleton I have looks like this:

My character looks like this:

One random note. The root bone is still part of the simulation even when using SetAllBodiesBelowSimulatePhysics. Only when I select whole upper body, the root bone stays in place. I assigned a camera into it and saw it moving wildly. To my understanding only the bones under specifiec bone should be part of the simulation, right? Is this normal?

Tested the same piece of code now with default UE character and example animations and the result looks pretty much the same. Blending back into animated state causes the mesh to spin around few times, however not in that violent way than with my own mesh and skeleton. Also the mesh is detached from the pawn and ends into random oriention.

Additionally I noticed that while the ragdoll is being blended out, the violence of it moving around relates from the value given SetAllBodiesBelowPhysicsBlendWeight. If I’ll give constant (I know its not the right way), it shakes very violently with value 0.1 and quite steadily with value 0.9.

You should take a look at feigning death in UnrealTournament,
In pre 4.8 feigning death was broken in UT, but it is working now;)

Hi. Thank you for the heads up. I will have a look on this tomorrow and see whether I can replicate it.

Unfortunately even with multiple attemps I have not been able to get it to work. When I assign capsule component under the mesh like in UT the ragdoll goes all wobbly. Going back from ragdoll causes the mesh to disappear and appear in correct position after the blendout. With my own approach where the mesh is placed under the capsule the ragdoll looks nice. However when I try to recover from it it works until the root bone is set a new transform. For some reason after that the whole mesh ends up into world zero location.

This seems impossible…

It works somehow in UT- probably because it is blending to crouch anim and it looks pretty good. I have problems with blending in 4.8 too, after 3 days of testing I’m still unable to blend ragdoll->anim, even with montage running it always blends through TPose or not blending at all.

Ok, It seems I finally found solution for this stuff. It works different than UT, because I changed 1 line of code in the engine and I’m able to blend ragdoll->anim even without simulation.

Can’t add everything in one comment :frowning:

Engine changes:

In the USkeletalMeshComponent::BlendPhysicsBones( TArray& InRequiredBones)

I changed:

if (BodyInstance->IsInstanceSimulatingPhysics())

to:

if (BodyInstance->IsInstanceSimulatingPhysics() || BodyInstance->PhysicsBlendWeight > 0.f)




bool USkeletalMeshComponent::ShouldRunPreClothTick() const
{
	//in my case I've enforced return value to true
	//because I'm handling where and when PreClothTick is ticking
	return true;
}

Functionality that prepare ragdoll for blending

PhysicsBlendWeight = 1.f; 
const FVector RagdollLoc = GetMesh()->GetBoneLocation(HipsBoneName) + FVector(0, 0, GetCapsuleComponent()->GetScaledCapsuleHalfHeight()) + FVector(0.f, 0.f, ExecutionZOffset); //get hips bone location, this is the place where capsule is teleported
FRotator RotationBoneAxis = GetMesh()->GetBoneAxis(GetUpBoneName, EAxis::X).Rotation(); //get ragdoll orientation
RotationBoneAxis.Pitch = 0;
RotationBoneAxis.Roll = 0;

if (IsLyingOnBack()) // this checks if ragdoll is upside down and selects correct animation
{
	MontageToPlay = GetUpBack;
	RotationBoneAxis.Yaw += 180.f;
}
else
{
	MontageToPlay = GetUpFront;
}

RotationBoneAxis = RotationBoneAxis.Clamp();


GetMesh()->KinematicBonesUpdateType = EKinematicBonesUpdateToPhysics::SkipAllBones; //this is crucial, because USkeletalMeshComponent::UpdateKinematicBonesToAnim will copy TPose bone locations to rigid bodies locations and we want to supress this logic

GetCapsuleComponent()->SetCollisionResponseToChannels(PreRagdollCapsuleCollisionResponseContainer); //restore collisions
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
SetActorLocationAndRotation(RagdollLoc, RotationBoneAxis); //set capsule location where it should be 


GetMesh()->SetSimulatePhysics(false); //turn off ragdoll simulation, without it blending will be broken because ragdoll will spin and eventually will fall under the floor 
SetPhysicsBlendWeight(1.f); //sets PhysicsBlendWeight on all BodyInstances below root again, because SetSimulatePhysics(false) resets them to 0.f

GetMesh()->SetRelativeLocationAndRotation(InitialMeshTranslation, InitialMeshRotation); // these are initial transformations I’ve cached them long time ago this way,
//because I didn’t know how to obtain defauls from the character skeletal mesh component:)
GetMesh()->AttachTo(GetCapsuleComponent());//reattach skeletal mesh component to capsule

//In >4.8.3 this is also crucial, because if you turn off simulation on the Skeletalmesh Component, the USkeletalMeshComponent::PreClothTick will never be called, and the blending will not work at all
GetMesh()->RegisterPreClothTick(true); 
GetMesh()->PreClothTickFunction.SetTickFunctionEnable(true);




GetCharacterMovement()->StopMovementImmediately();
GetCharacterMovement()->SetDefaultMovementMode();

bUseControllerRotationYaw = false;



float Duration = PlayAnimMontage(MontageToPlay);

GetWorldTimerManager().SetTimer(TimerHandle_StopFeignDeath,this, &AHatredBaseCharacter::StopFeignDeath, Duration, false);

//this in theory loads first frame of the MontageToPlay animation to SpaceBases
if (!GetMesh()->ShouldTickPose())
{
	GetMesh()->TickAnimation(0.0f);
	GetMesh()->RefreshBoneTransforms();
	GetMesh()->UpdateComponentToWorld();
}

Then in tick of your character interpolate PhysicsBlendWeight from 1.f to 0.f

At 0.f

set back, or to default
GetMesh()->KinematicBonesUpdateType = EKinematicBonesUpdateToPhysics::SkipSimulatingBones;

Restore skeletal mesh collisions and you are in the home:0

Hi and thanks from very detailed information! I’m not very eager to customize the engine because upgrading into new UE versions might make life miserable. I will definetely will look your example and try to get it working on my project also. Hopefully I could come up with an approach which wouldn’t require customizing the engine at all.

I will get back to you asap what I could come up with…

Has anyone found a solution to this (without changing the engine) - I m in a similar situation. When my character is on the floor after ragdoll activation and I try to use blend physics it goes all kinds of crazy and spins around…

As of now I cannot think of a way to do this other than the one provided by . I’ll be looking into this further and I’ll get back to you if I have any information related to a solution.

Hey ,

I’m having the same issue however I followed your instructions and it didn’t fully solve my problem. It only works if I don’t use the blending… if I enable the blending, it spins widly like others have mentioned and gets stuck in the air.

In your response, you mentioned setting the CapsuleComponent back to default collision settings but I can’t see where you detailed what you set them to when going into a Ragdoll state. I wish this was easier but the issue has been tying me up the past couple of days.

, do you happen to have an update as of yet on this?

Thanks!

EDIT: In the meantime, I have a funny feeling that the Capsule Collision is what’s doing this and trying to push back resetting collision to Tick to see if that hopefully helps.

Hi , did you changed engine code? This is critical part of blending.
if (BodyInstance->IsInstanceSimulatingPhysics() || BodyInstance->PhysicsBlendWeight > 0.f)

Hey ! Thanks for the quick response.

I didn’t and am unable to for this specific project at this time. I did come across another thread (Using Blend Physics Weight causes skeletal mesh to spin at high speed - World Creation - Epic Developer Community Forums) where this problem is also mentioned and was replicated as a bug within the engine. Possibly why you had to update the engine code.

I came across Jonas’s videos who also encountered this problem (Ragdoll 101 - Part 4 A few words on full body blend between animation and physics - YouTube) and his solution works for me within PHAT, but when I enable ragdoll, the character is literally shot off into the void.

I am setting the collision profile of the Mesh to “Ragdoll” and that won’t collide with the Capsule but for some reason isn’t working. I’m waiting for a response from Hardister so I hope I can figure this out as this issue is holding me up on this one feature :stuck_out_tongue:

But thanks for contacting me back and hope to get this resolved :slight_smile:

Sooner or later EPIC will implement/fix correct behavior, this feature was used for feigning death in Unreal Tournament :slight_smile:

Yea, I’ve noticed a couple people have said that which I may need to pull down the code to look at. I’ve given a little bit of code and a link to Jonas’s video so I’m hoping it might give them some more insight on the problem. Let me ask you, did you encounter the issue in Jonas’s video and was this change to the code more or less fixing the blending in and out?

Let me ask you, did you encounter the issue in Jonas’s video and was this change to the code more or less fixing the blending in and out?

Which issue? I watched whole video and didn’t saw any:) - If your character is shooting into the void you probably have a “intercollision” problem between ragdoll and ground or maybe ragdoll collide with this tiny box within it. You should debug this issue with https://developer.nvidia.com/physx-visual-debugger

Thanks for the link… This is more of a blending problem as it doesn’t happen unless I attempt to blend but I’ll use that to see if it points anything out. But then again…

My CollisionCapsule isn’t colliding with the Mesh and vice versa but it could be possible that during the first bits of the blend, it happens to translate into the floor and then conflicting collision that sends it out of control. What I might do is I’m currently updating the CapsuleComponent while in Ragdoll and its possible doing that while the blending/anim is taking place, that its pushing that into the floor :stuck_out_tongue: That might be a good start to check out :slight_smile:

“Which issue? I watched whole video and didn’t saw any:)”
The issue starts at 2:00 into the video. He shows how the physics blending goes out of control with animations and he uses a body added to the root and sets to kinematic to fix it :slight_smile: