In Lyra project, where is this "Ground distance" come from?


I can’t find where the value set, only get node, thank you

All variables in Lyra animations are set in the function BlueprintThreadSafeUpdateAnimation

Look through there. It calls other functions. One of those sets Ground Distance.

thank you

1 Like

I don’t think so. There’s no set groound distance in any of these functions. I looked it through like lots of times.

The GroundDistance variable is set via C++ in the function:

void ULyraAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
	Super::NativeUpdateAnimation(DeltaSeconds);

	const ALyraCharacter* Character = Cast<ALyraCharacter>(GetOwningActor());
	if (!Character)
	{
		return;
	}

	ULyraCharacterMovementComponent* CharMoveComp = CastChecked<ULyraCharacterMovementComponent>(Character->GetCharacterMovement());
	const FLyraCharacterGroundInfo& GroundInfo = CharMoveComp->GetGroundInfo();
	GroundDistance = GroundInfo.GroundDistance;
}
const FLyraCharacterGroundInfo& ULyraCharacterMovementComponent::GetGroundInfo()
{
	if (!CharacterOwner || (GFrameCounter == CachedGroundInfo.LastUpdateFrame))
	{
		return CachedGroundInfo;
	}

	if (MovementMode == MOVE_Walking)
	{
		CachedGroundInfo.GroundHitResult = CurrentFloor.HitResult;
		CachedGroundInfo.GroundDistance = 0.0f;
	}
	else
	{
		const UCapsuleComponent* CapsuleComp = CharacterOwner->GetCapsuleComponent();
		check(CapsuleComp);

		const float CapsuleHalfHeight = CapsuleComp->GetUnscaledCapsuleHalfHeight();
		const ECollisionChannel CollisionChannel = (UpdatedComponent ? UpdatedComponent->GetCollisionObjectType() : ECC_Pawn);
		const FVector TraceStart(GetActorLocation());
		const FVector TraceEnd(TraceStart.X, TraceStart.Y, (TraceStart.Z - LyraCharacter::GroundTraceDistance - CapsuleHalfHeight));

		FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(LyraCharacterMovementComponent_GetGroundInfo), false, CharacterOwner);
		FCollisionResponseParams ResponseParam;
		InitCollisionParams(QueryParams, ResponseParam);

		FHitResult HitResult;
		GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, CollisionChannel, QueryParams, ResponseParam);

		CachedGroundInfo.GroundHitResult = HitResult;
		CachedGroundInfo.GroundDistance = LyraCharacter::GroundTraceDistance;

		if (MovementMode == MOVE_NavWalking)
		{
			CachedGroundInfo.GroundDistance = 0.0f;
		}
		else if (HitResult.bBlockingHit)
		{
			CachedGroundInfo.GroundDistance = FMath::Max((HitResult.Distance - CapsuleHalfHeight), 0.0f);
		}
	}

	CachedGroundInfo.LastUpdateFrame = GFrameCounter;

	return CachedGroundInfo;
}

This is the code, and I hope this info helps :slight_smile:

4 Likes

Very nice, thank you.

What can we use in our project as a replacement for Ground Distance? I have a Blueprint project and I’m trying to use the Lyra animation system, but stuck on trying to figure to out a good replacement for the custom Ground Distance function.

1 Like

Set up a function that runs every frame(not thread safe since you’ll use line trace). Get capsule component half height, line trace from the character’s actor location straight down, get the hit location and then do some subtraction.

Thanks for the tips! I’m trying to do this, but currently can’t find a way to get the Capsule Height.
I see GetUnscaledCapsuleHalfHeight mentioned in C+ above, but not sure how to access it in Blueprints.

*2

If math is not an opinion, you have half…

Get your character actor , then get component by class (capsule component), then get scaled capsule half height, use your character world location to subtract capsule half height, that would be your feet location.

Up to .27, If you query from the movement component, you actually can get the result of the ground distance off the trace which is constantly running off the bottom of the capsule. Without any need for additional traces.

When possible, avoid useless/extra traces…

You have direct acess to the current floor variable.

You have findfloor, and computefloordistance which you can choose from.
Compute is an extra trace.

Stuff is sorted under the variables>character movement walking
and pawn>components>character movement.

Ps:
Current floor > break > hit result > break > impact point > is the v3 of the actual floor.

1 Like

i coudln’t find the source in lyra project. where can it find it?

i coudln’t find the source in Lyra project. is it in lyra project or where can i see it?