Root motion doesn't move in the z-axis!

Hey I came up with another solution to the problem that doesn’t require changing the movement mode to flying. If you’re using C++ and a custom character movement component you can simply override the UCharacterMovementComponent::ConstrainAnimRootMotionVelocity
function. As you can see, in its implementation it is preventing the Z value from being overwritten:

FVector UCharacterMovementComponent::ConstrainAnimRootMotionVelocity(const FVector& RootMotionVelocity, const FVector& CurrentVelocity) const
{
	FVector Result = RootMotionVelocity;

	// Do not override Velocity.Z if in falling physics, we want to keep the effect of gravity.
	if (IsFalling())
	{
		Result.Z = CurrentVelocity.Z;
	}

	return Result;
}

I removed this in my override function like so and it worked great :slight_smile:

FVector UCustomCharacterMovementComponent::ConstrainAnimRootMotionVelocity(const FVector& RootMotionVelocity, const FVector& CurrentVelocity) const
{
	return RootMotionVelocity;
}
10 Likes