Skip to content

Commit

Permalink
Fixed Feet IK
Browse files Browse the repository at this point in the history
  • Loading branch information
kvoeten committed Mar 11, 2021
1 parent b2ae30f commit 6913f10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Binary file modified Content/Blueprints/ABP_IKBody.uasset
Binary file not shown.
Binary file added Content/Blueprints/BP_PawnDummy.uasset
Binary file not shown.
35 changes: 18 additions & 17 deletions Source/UnrealBody/Private/Animation/IKCharacterAnimInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,42 @@ void UIKCharacterAnimInstance::UpdateFootIK()
void UIKCharacterAnimInstance::TraceFoot(FVector Foot, FVector* ResultLocation,
FRotator* ResultRotation, UWorld* World, FCollisionQueryParams* Params)
{
// Establish trace starting point
FVector Start = FVector(Foot.X, Foot.Y, Foot.Z + 60);
// Establish trace start & end point
const float ZRoot = GetOwningComponent()->GetComponentLocation().Z;
const FVector Start = FVector(Foot.X, Foot.Y, ZRoot + 60);
const FVector End = FVector(Foot.X, Foot.Y, ZRoot);

// Trace
FHitResult HitResult; // Establish Hit Result
World->LineTraceSingleByChannel(HitResult, Start, Foot, ECC_Visibility, *Params);
World->LineTraceSingleByChannel(HitResult, Start, End, ECC_Visibility, *Params);

// Check for hit
if (HitResult.bBlockingHit)
{
const FVector ImpactLocation = HitResult.Location;
const FVector ImpactNormal = HitResult.ImpactNormal;

if (ImpactLocation.Z > Foot.Z)
if (ImpactLocation.Z > ZRoot)
{
// Create additive vector for Z position
*ResultLocation = FVector(UKismetMathLibrary::Abs(ImpactLocation.Z - Foot.Z), 0, 0);
ResultLocation->X = UKismetMathLibrary::Abs(ImpactLocation.Z - ZRoot);

// Calculate and set new rotation
ResultRotation->Roll = UKismetMathLibrary::Atan2(ImpactNormal.Y, ImpactNormal.Z);
ResultRotation->Pitch = UKismetMathLibrary::Atan2(ImpactNormal.X, ImpactNormal.Z);
ResultRotation->Yaw = 0;

// Return to confirm settings
return;
}

// Maintain the settings from the previous tick
return;
}
else
{
ResultLocation->X = 0;
ResultLocation->Y = 0;
ResultLocation->Z = 0;
ResultRotation->Roll = 0;
ResultRotation->Pitch = 0;
ResultRotation->Yaw = 0;
}

// Set defaults if no trace success
ResultLocation->X = 0;
ResultRotation->Roll = 0;
ResultRotation->Pitch = 0;
}

void UIKCharacterAnimInstance::UpdateHeadValues()
Expand Down Expand Up @@ -143,8 +146,6 @@ void UIKCharacterAnimInstance::UpdateHandValues()
// Hand Rotations are controller rotations
ArmIKValues.LeftHandRotation = this->BodyComponent->LeftController->GetComponentRotation();
ArmIKValues.RightHandRotation = this->BodyComponent->RightController->GetComponentRotation();

UE_LOG(LogIKBodyAnimation, Warning, TEXT("RHandLoc: %f, %f"), ArmIKValues.LeftHandLocation.X, ArmIKValues.LeftHandLocation.Y)
}

void UIKCharacterAnimInstance::UpdateMovementValues(float DeltaSeconds)
Expand Down

0 comments on commit 6913f10

Please sign in to comment.