APawn based character teleports on ragdoll

My characters are APawn based instead of ACharacter based. My character C++ still has capsule and skeletal mesh, and their construction is pretty much copied from the ACharacter code.

I used APawn because the character movement based component kept messing with my custom movement code. My game is tile based and I don’t use direction / speed based movement, but rather end tile based movement (it moves directly towards the end tile and wont go further). This works all great, but the only problem is the ragdoll teleporting to the position where the character started when they die (become ragdoll).

I have tried a bunch of things:

GetMesh()->SetRelativeLocation(FVector(0,0,-ENTRULIAN_HEIGHT), false, NULL, ETeleportType::TeleportPhysics);
GetMesh()->SetAllPhysicsPosition(GetMesh()->GetComponentLocation());
GetMesh()->SetSimulatePhysics(true);
GetMesh()->UpdateKinematicBonesToAnim(GetMesh()->GetComponentSpaceTransforms(), ETeleportType::TeleportPhysics, false);
GetMesh()->SetAllPhysicsLinearVelocity(FVector::ZeroVector);

But none of them seem to work. I also tried looking at the ACharacter code to see if there was anything special there, but I think most of it was just related to networking.

I am also not yet 100% sure but it also seems that when I do traces against the character mesh it returns old positions?

Can you give more code about this?
Can be this because of root motion animation? or your custom movement component is not moving capsule well?

I haven’t defined a movement component. I update movement with this code:

bool AEntruliaCharacter::MoveIntoPosition(const FVector &End, float DeltaSeconds, bool Strict, bool Rotate)
{
	FVector Start = GetActorLocation();
	FVector Dist = End - Start;
	Dist[2] = 0.0f;

	float flMax = Strict ? 1.0f : SMOOTH_MOVEMENT_DISTANCE;

	float flDist = Dist.Size();
	if (flDist >= flMax)
	{
		float flTargetSpeed = ModifyMovementSpeed(CharacterInfo->RunSpeed, true);

		float flTarget = UEntruliaUtils::RemapFloatClamped(flDist, 8.0f, 32.0f, 0.1f, 1.0f) * flTargetSpeed;
		MovementSpeed = UEntruliaUtils::Approach(flTarget, MovementSpeed, DeltaSeconds * Acceleration);
		Dist.Normalize();
		MovementDirection = Dist;

		float flMove = FMath::Min(flDist, MovementSpeed * DeltaSeconds);
		Start = Start + (Dist * flMove);
		Start[2] = ENTRULIAN_HEIGHT;

		FindFloor(Start);

		SetActorLocation(Start, false, NULL, ETeleportType::TeleportPhysics);

		if (Rotate)
			SetActorRotation(Dist.Rotation());

		return false;
	}
	else if (!Strict)
		return true;

	Start = End;
	FindFloor(Start);

	SetActorLocation(Start, false, NULL, ETeleportType::TeleportPhysics);
	return true;
}

I don’t have root motion in my animations.

Hello,

Do you have a default state for your animations? The problem could be that your Pawn/Character doesn’t have an animation to default to.

Thanks,

I don’t know if animation blueprint somehow stops playing when the character becomes ragdoll. I certainly don’t call anything to stop the blueprint from happening. It should play the default idle blend animation. It’s strange since I didn’t have this problem when I was still using ACharacter as the base instead of APawn. Though, it’s possible it happened when I moved to 4.19 and I just didn’t notice the problem until after I switched to APawn as well.