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

View File

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