Removed legacy feet position and replaced by calculating theirs distance by IK feet and target.

Fixed Pivot condition for velocity direction that does not corresponding to player input.
This commit is contained in:
LongLy 2025-07-27 10:06:15 +07:00
parent 226368b178
commit 501111ec24
6 changed files with 37 additions and 22 deletions

View File

@ -3,6 +3,7 @@
#include "AnimInstances/OLSBaseLinkedLayerAnimInstance.h"
#include "KismetAnimationLibrary.h"
#include "AnimInstances/OLSBaseLayerAnimInstance.h"
void UOLSBaseLinkedLayerAnimInstance::NativeInitializeAnimation()
@ -58,26 +59,37 @@ void UOLSBaseLinkedLayerAnimInstance::NativeThreadSafeUpdateSkeletonControlData(
{
OrientationWarpingAlpha = GetCurveValue(EnableOrientationWarpingName);
const float feetPositionValue = GetCurveValue(FeetPositionCurveName);
bIsRightFootPlanted = feetPositionValue > 0.5f;
bIsLeftFootPlanted = FMath::Abs(feetPositionValue) > 0.5f;
bIsLeftFootFarFromTarget = UKismetAnimationLibrary::K2_DistanceBetweenTwoSocketsAndMapRange(
GetOwningComponent(), IKFootLeft, RTS_World,
IKTargetFootLeft, RTS_World, false,
0.f, 0.f, 0.f, 0.f) > 8.0f;
bIsRightFootFarFromTarget = UKismetAnimationLibrary::K2_DistanceBetweenTwoSocketsAndMapRange(
GetOwningComponent(), IKFootRight, RTS_World,
IKTargetFootRight, RTS_World, false,
0.f, 0.f, 0.f, 0.f) > 8.0f;
// const float feetPositionValue = GetCurveValue(FeetPositionCurveName);
// bIsRightFootPlanted = feetPositionValue > 0.5f;
// bIsLeftFootPlanted = FMath::Abs(feetPositionValue) > 0.5f;
// If neither foot is planted, use the last valid foot
if (!bIsRightFootPlanted && !bIsLeftFootPlanted)
if (!bIsRightFootFarFromTarget && !bIsLeftFootFarFromTarget)
{
if (bWasRightFootPlantingChanged)
{
bIsRightFootPlanted = true;
bIsRightFootFarFromTarget = true;
}
else
{
bIsLeftFootPlanted = true;
bIsLeftFootFarFromTarget = true;
}
}
else
{
// Update the last valid foot
bWasRightFootPlantingChanged = bIsRightFootPlanted;
bWasRightFootPlantingChanged = bIsRightFootFarFromTarget;
}
}
@ -157,7 +169,7 @@ UAnimSequence* UOLSBaseLinkedLayerAnimInstance::SelectStartCycleAnimation(const
return GetGaitAnimSets(isCrouching, gait).GaitAnimSet_ForwardFacing.StartCycle.
GetMovementAnimationByAngle(
velocityDirection, angle, bIsRightFootPlanted);
velocityDirection, angle, bIsRightFootFarFromTarget);
}
UAnimSequence* UOLSBaseLinkedLayerAnimInstance::SelectCycleAnimation(const bool isCrouching,
@ -189,7 +201,7 @@ UAnimSequence* UOLSBaseLinkedLayerAnimInstance::SelectPivotAnimation(const bool
}
return GetGaitAnimSets(isCrouching, gait).GaitAnimSet_ForwardFacing.Pivot.GetLeftOrRightByAngle(
angle, bIsLeftFootPlanted, bIsRightFootPlanted);
angle, bIsLeftFootFarFromTarget, bIsRightFootFarFromTarget);
}
UAnimSequence* UOLSBaseLinkedLayerAnimInstance::SelectStopCycleAnimation(const bool isCrouching,
@ -205,7 +217,7 @@ UAnimSequence* UOLSBaseLinkedLayerAnimInstance::SelectStopCycleAnimation(const b
GetMovementAnimationByCardinalDirection(velocityDirection);
}
return GetGaitAnimSets(isCrouching, gait).GaitAnimSet_ForwardFacing.StopCycle.GetLeftOrRightAnim(bIsRightFootPlanted);
return GetGaitAnimSets(isCrouching, gait).GaitAnimSet_ForwardFacing.StopCycle.GetLeftOrRightAnim(bIsRightFootFarFromTarget);
}
FVector2D UOLSBaseLinkedLayerAnimInstance::SelectPlayRateByLocomotionState(
@ -294,7 +306,7 @@ void UOLSBaseLinkedLayerAnimInstance::ProcessTurnInPlaceTransitionLogic(const fl
bool UOLSBaseLinkedLayerAnimInstance::ShouldSelectNewPivotAnimation(const float lastPivotTime) const
{
return ShouldLookingOrAimingDirectionSelectNewPivotAnimation(lastPivotTime) || ShouldVelocityDirectionSelectNewPivotAnimation(lastPivotTime);
return ShouldLookingOrAimingDirectionSelectNewPivotAnimation(lastPivotTime);
}
bool UOLSBaseLinkedLayerAnimInstance::ShouldLookingOrAimingDirectionSelectNewPivotAnimation(const float lastPivotTime) const
@ -302,11 +314,6 @@ bool UOLSBaseLinkedLayerAnimInstance::ShouldLookingOrAimingDirectionSelectNewPiv
return (bIsLookingOrAimingDirection && lastPivotTime > 0.0f);
}
bool UOLSBaseLinkedLayerAnimInstance::ShouldVelocityDirectionSelectNewPivotAnimation(const float lastPivotTime) const
{
return (bIsLookingOrAimingDirection && lastPivotTime > 0.0f && bWasRightFootPlantingChanged != bIsRightFootPlanted);
}
UOLSBaseLayerAnimInstance* UOLSBaseLinkedLayerAnimInstance::GetBaseMainAnimInstance() const
{
return BaseMainAnimInstance;

View File

@ -120,9 +120,6 @@ protected:
UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe), Category = "ThreadSafe|Pivot")
bool ShouldLookingOrAimingDirectionSelectNewPivotAnimation(const float lastPivotTime) const;
UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe), Category = "ThreadSafe|Pivot")
bool ShouldVelocityDirectionSelectNewPivotAnimation(const float lastPivotTime) const;
protected:
UFUNCTION(BlueprintCallable, meta = (BlueprintThreadSafe))
@ -202,17 +199,16 @@ protected:
UPROPERTY(BlueprintReadWrite, Category = "ThreadSafe|SkeletonControl|OrientationWarping")
float OrientationWarpingAlpha = 0.f;
protected:
UPROPERTY(BlueprintReadWrite, Category = "ThreadSafe|SkeletonControl|FeetPosition")
uint8 bWasRightFootPlantingChanged : 1 = false;
UPROPERTY(BlueprintReadWrite, Category = "ThreadSafe|SkeletonControl|FeetPosition")
uint8 bIsRightFootPlanted : 1 = true;
uint8 bIsRightFootFarFromTarget : 1 = true;
UPROPERTY(BlueprintReadWrite, Category = "ThreadSafe|SkeletonControl|FeetPosition")
uint8 bIsLeftFootPlanted : 1 = true;
uint8 bIsLeftFootFarFromTarget : 1 = true;
protected:
@ -269,6 +265,18 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings|AnimSet|FeetPosition")
FName FeetPositionCurveName = NAME_None;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings|AnimSet|FeetPosition")
FName IKFootRight = NAME_None;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings|AnimSet|FeetPosition")
FName IKTargetFootRight = NAME_None;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings|AnimSet|FeetPosition")
FName IKFootLeft = NAME_None;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings|AnimSet|FeetPosition")
FName IKTargetFootLeft = NAME_None;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings|StrideWarping")
float StrideWarpingBlendInDurationScaled = .2f;