I am using a gengine log that is returning 68.0f. I feel like I am extremely close to the answer I just need to get a value of zero. I am trying to get the distance between the floor and the character himself in order to make a falling function without using find floor() because I am trying to check the general elevation of the character relative to the blocking hit not the surface that the character is standing on. That is why I am using a multi linetrace channel.
I found this on the ue4 forums: How to calculate player height from ground?
Nabiul’s explanation is what I am looking at. I need just a better explanation how to do what Nabiul said in relation with c++ rather than blueprints. I saw Namsh’s explanation but I see a flaw that retains to the collision of the object that you are standing on. FindFloor()'s distance is reset to zero because the new object’s collision (that is at a higher elevation relative to the base floor) is blocking the line trace that findfloor uses. If FindFloor() were to have a collision channel specified that you could ignore using unreal that would have been nice.
FRotator AEnemyCharacter::SpineCalculation()
{
if (AMainCharacter* Player = Cast<AMainCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0)))
{
//Attaching to a socket rather then attaching to the capsule component.
//Attaching specifically to the foot of the character so that I may potentially return a value close
//to zero or zero. The foot is the closet to the floor.
FVector StartTrace = Player->GetMesh()->GetSocketLocation("FootSocket");
//Linetrace's start point rotation is relative to this socket.
FRotator SocketRotation = Player->GetMesh()->GetSocketRotation("FootSocket");
FCollisionResponseParams ResponseParams;
FCollisionQueryParams QueryParams = FCollisionQueryParams(SCENE_QUERY_STAT(FallingTrace), false, this);
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
//Ignoring the player's mesh.
QueryParams.AddIgnoredComponent(Player->GetMesh());
//An array of FHitresults.
TArray<FHitResult> Hit;
//The endtrace's distance rotation and start location.
FVector EndTrace = StartTrace + SocketRotation.Vector() * 1000.0f;
//To be able to see the line trace in the world space.
DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor(255, 0, 0), false, -1, 0, 1.333);
//Multi line trace that may pass through multiple object until a blocking hit is possible.
if (GetWorld()->LineTraceMultiByChannel(Hit, StartTrace, EndTrace, ECollisionChannel::ECC_Visibility, QueryParams, ResponseParams))
{
//For looping through the results until a blocking hit is reached.
for (FHitResult& Results : Hit)
{
//Checking to see if a blocking hit has connected with any actor.
if (AActor* ActorLocation = Cast<AActor>(Results.GetActor()))
{
//Using .Size() to return a float value using the Endtrace's length.
//Substracting the total length of the line trace and the distance of the hit result. The hit result is of a smaller //value due to the blocking hit that obstructs the linetrace's full length.
float LineDistanceCal = EndTrace.Size() - Results.Distance;
//Substracting the difference of the calculation with the capsule component's height using ZAxisVector.Size() hoping to return a value that is equal to zero.
float DistanceBetweenCapsuleAndLine = (LineDistance - Player->GetCapsuleComponent()->GetComponentLocation().ZAxisVector.Size();
//Checking the Distance at runtime using GEngine.
GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Orange, FString::Printf(TEXT("Here is the spacelocation: %f"), DistanceBetweenCapsuleAndLine ));
}
}
}
}
}