Hello all,
I need to get the closest hit to player on this sphere trace, from the attached image I am getting the furthest hit. Here is my trace…
// Trace for Ledge
FHitResult LHitOut(ForceInit);
UKismetSystemLibrary::SphereTraceSingle(this, LStart, LEnd, 20.0f, UEngineTypes::ConvertToTraceType(ECC_GameTraceChannel2), true, toignore, EDrawDebugTrace::ForOneFrame, LHitOut, true);
and here is the full routine:
void AGMaxCharacter::SeekLedge()
{
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
//WALL AND LEDGE TRACE PARAMS
const FVector WStart = myCharacter->GetActorLocation();
FRotator FR = myCharacter->GetActorRotation();
FVector FV = UKismetMathLibrary::GetForwardVector(FR);
FVector WL = FV * 70.0f;
const FVector WEnd = FVector(FV.X * 150.0f, FV.Y * 150.0f, FV.Z) + WStart;
const FVector LStart = FVector(WL.X, WL.Y, WL.Z) + FVector(WStart.X, WStart.Y, WStart.Z + 500.0f);
const FVector LEnd = FVector(LStart.X, LStart.Y, (LStart.Z - 500.0f));
//Trace for Wall
FHitResult WHitOut(ForceInit);
TArray<AActor*> toignore;
UKismetSystemLibrary::SphereTraceSingle(this, WStart, WEnd, 20.0f, UEngineTypes::ConvertToTraceType(ECC_GameTraceChannel2), false, toignore, EDrawDebugTrace::ForOneFrame, WHitOut, true);
// Trace for Ledge
FHitResult LHitOut(ForceInit);
UKismetSystemLibrary::SphereTraceSingle(this, LStart, LEnd, 20.0f, UEngineTypes::ConvertToTraceType(ECC_GameTraceChannel2), true, toignore, EDrawDebugTrace::ForOneFrame, LHitOut, true);
WallLocation = WHitOut.Location;
WallNormal = WHitOut.Normal;
LedgeLocation = LHitOut.Location;
FVector SocketLocation = GetMesh()->GetSocketLocation("PelvisSocket");
LocalDistanceToLedge = (SocketLocation.Z - LedgeLocation.Z);
if (((SocketLocation.Z - LedgeLocation.Z) > -71.0f && (SocketLocation.Z - LedgeLocation.Z) < 1.0f) && LocalIsClimbingLedge == false)
{
LocalCanGrabLedge = true;
GrabLedge();
}else{
LocalCanGrabLedge = false;
}
}
Appreciate any help!!!
Thanks.