Converting BP to C++ Need help In a Foot Placement Function

Hello I am Fairly new to C++ Programming in UE 4 and Learning I was Converting a Ik leg Functionality from BP to Cpp And i am Stuck on a Particular point in My converting

void AUeEg_26Character::FootDisplacement(FName Name, float& dist, bool& blockhit)

FVector InVec = GetMesh()->GetComponentLocation() + FVector(0, 0, 96);
FVector InSocketVec = GetMesh()->GetSocketLocation(Name);
FVector NewVector = UKismetMathLibrary::MakeVector(InSocketVec.X, InSocketVec.Y, InVec.Z);

FHitResult HitResults;
FVector StartTrace = NewVector;
FCollisionQueryParams Params;
FVector EndTrace = NewVector - FVector(0, 0, 151);

GetWorld()->LineTraceSingleByChannel(HitResults, StartTrace, EndTrace, ECC_Visibility, Params);
UKismetSystemLibrary::DrawDebugLine(GetWorld(), StartTrace, EndTrace, FLinearColor::Red, false, 2.0f);
blockhit = HitResults.bBlockingHit;
dist = HitResults.Distance;
Distance = dist;
HitTargets = blockhit;


void AUeEg_26Character::LineTraceFoot(FName Name, FVector& HitTracetNormal, float& Dist)


FVector ActSocketLoc = GetMesh()->GetSocketLocation(Name);
FVector ActRootLoc = GetMesh()->GetSocketLocation(FName("root"));
FVector InVec = UKismetMathLibrary::MakeVector(ActSocketLoc.X, ActSocketLoc.Y, ActRootLoc.Z);

FHitResult HitResults;

FVector TraceStart = InVec + FVector(0, 0, 100);
FVector TraceEnd = InVec - FVector(0, 0, 100);
FCollisionQueryParams Params;
/*bool LegSphereTrace= UKismetSystemLibrary::SphereTraceSingle(GetWorld(), TraceStart, TraceEnd, 5.0f, ETraceTypeQuery::TraceTypeQuery1, false, TArray<AActor*>(), EDrawDebugTrace::ForDuration
	, HitResults, true, FLinearColor::Red, FLinearColor::Green, 5.0f);*/
if (GetWorld()->LineTraceSingleByChannel(HitResults, TraceStart, TraceEnd, ECC_Visibility, Params))
	UKismetSystemLibrary::DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FLinearColor::Red, false, 2.0f);
	HitTracetNormal = HitResults.Normal;
	Dist = HitResults.Distance;
	Dist = 999.f;
	HitTracetNormal = FVector(0, 0 , 0);


void AUeEg_26Character::IkFootPlacement()

if (!GetCharacterMovement()->IsFalling())
	float RDistance; //= Distance;
	bool bIsRHit; //= HitTargets;
	float LDistance; //= Distance;
	bool bIsLHit;//= HitTargets;
	FootDisplacement("foot_r", RDistance, bIsRHit);
	FootDisplacement("foot_l", LDistance, bIsLHit);
	if (bIsRHit || bIsLHit)
		if (LDistance >= RDistance) {
			UE_LOG(LogTemp, Warning, TEXT(" FootIk"))

I think after this part the problem is happening the Mesh root seems to be on top of the capsule location.

				float PickA = UKismetMathLibrary::SelectFloat(LDistance, RDistance, HitTargets);
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Some variable values: %s"), PickA));*/
				UE_LOG(LogTemp, Warning, TEXT(" %s"), *FString::SanitizeFloat(PickA))
			float Target = PickA - 98.f * (-1);
			float Interp = UKismetMathLibrary::FInterpTo_Constant(LegDisplacement, Target, GetWorld()->GetDeltaSeconds(), 15.f);

			LegDisplacement = Interp;
		FVector RHitTrace;
		float RDist;
		//bool _bIsRHit;
			LineTraceFoot("foot_r", RHitTrace, RDist);
			float Attan1 = UKismetMathLibrary::DegAtan2(RHitTrace.Y, RHitTrace.Z);
			float Attan2 = UKismetMathLibrary::DegAtan2(RHitTrace.X, RHitTrace.Z)*-(1);
			FRotator InRVal = UKismetMathLibrary::MakeRotator(Attan1, Attan2, 0.0f);
			FRotator RRotInterp = UKismetMathLibrary::RInterpTo(RRot_Imp, InRVal, GetWorld()->GetDeltaSeconds(), 15.f);
			RRot_Imp = RRotInterp;

			float InFval = RDist - 110.f / (-45.f);
			float RIk = UKismetMathLibrary::FInterpTo(RIk_Impl, InFval, GetWorld()->GetDeltaSeconds(), 15.f);
			RIk_Impl = RIk;

			FVector LHitTrace;
			float LDist;
			//bool _bIsLHit;
			LineTraceFoot("foot_l", LHitTrace, LDist);
			float LAttan1 = UKismetMathLibrary::DegAtan2(LHitTrace.Y, LHitTrace.Z);
			float LAttan2 = UKismetMathLibrary::DegAtan2(LHitTrace.X, LHitTrace.Z) * (-1);
			FRotator LInRVal = UKismetMathLibrary::MakeRotator(LAttan1, LAttan2, 0.0f);
			FRotator LRotInterp = UKismetMathLibrary::RInterpTo(LRot_Imp, LInRVal, GetWorld()->GetDeltaSeconds(), 15.f);
			LRot_Imp = LRotInterp;
			float LInFval = LDist - 110.f / (-45.f);
			float LIk = UKismetMathLibrary::FInterpTo(LIk_Impl, LInFval, GetWorld()->GetDeltaSeconds(), 15.f);
			LIk_Impl = LIk;



what I think is Causing the problem

  1. The Select From Function is the Problem.
  2. I am not able to make use of the referenced Boolean and float properly in IK FootPlacement Function.

seniors Please i need to move forward your help is very much needed here.

I think the equivalent of SelectFloat in C++ would be this:

    float A;
    float B;
    bool PickA;
    float ReturnValue;
    if (PickA)
      ReturnValue = A;
      ReturnValue = B;

Thank you for your reply I thought my post was dead lol, ill try to apply it and let you know thank you for replying it means a lot

Its working now thanks @GrumbleBunny, my math was way wrong in the last part did some correction there and Leg ik With Slope detection is working fine now to my fellow Gamedevs the codes are perfect if any one wants a Ik Leg lol its all here.