2024-09-22 21:11:19 +00:00
|
|
|
// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
|
|
|
|
|
|
|
|
|
|
|
|
#include "Libraries/OLSLocomotionBPLibrary.h"
|
|
|
|
|
2024-11-24 19:32:47 +00:00
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogOLSLocomotionLibrary, Verbose, All);
|
|
|
|
|
2024-09-22 21:11:19 +00:00
|
|
|
EOLSCardinalDirection UOLSLocomotionBPLibrary::SelectCardinalDirectionFromAngle(float angle,
|
|
|
|
float deadZone,
|
|
|
|
EOLSCardinalDirection currentDirection,
|
|
|
|
bool useCurrentDirection /* = false */)
|
|
|
|
{
|
|
|
|
|
|
|
|
const float absAngle = FMath::Abs(angle);
|
|
|
|
float fwdDeadZone = deadZone;
|
|
|
|
float bwdDeadZone = deadZone;
|
|
|
|
|
|
|
|
if (useCurrentDirection)
|
|
|
|
{
|
|
|
|
if (currentDirection == EOLSCardinalDirection::EForward)
|
|
|
|
{
|
|
|
|
fwdDeadZone *= 2.f;
|
|
|
|
}
|
|
|
|
else if (currentDirection == EOLSCardinalDirection::EBackward)
|
|
|
|
{
|
|
|
|
bwdDeadZone *= 2.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(absAngle <= (45 + fwdDeadZone))
|
|
|
|
{
|
|
|
|
return EOLSCardinalDirection::EForward;
|
|
|
|
}
|
|
|
|
else if (absAngle >= (135 - bwdDeadZone))
|
|
|
|
{
|
|
|
|
return EOLSCardinalDirection::EBackward;
|
|
|
|
}
|
|
|
|
else if (angle > 0)
|
|
|
|
{
|
|
|
|
return EOLSCardinalDirection::ERight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EOLSCardinalDirection::ELeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLSCardinalDirection UOLSLocomotionBPLibrary::GetOppositeCardinalDirectional(EOLSCardinalDirection currentDirection)
|
|
|
|
{
|
|
|
|
switch (currentDirection)
|
|
|
|
{
|
|
|
|
case EOLSCardinalDirection::EForward: {return EOLSCardinalDirection::EBackward;}
|
|
|
|
case EOLSCardinalDirection::EBackward: {return EOLSCardinalDirection::EForward;}
|
|
|
|
case EOLSCardinalDirection::ELeft: {return EOLSCardinalDirection::ERight;}
|
|
|
|
case EOLSCardinalDirection::ERight: {return EOLSCardinalDirection::ELeft;}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EOLSCardinalDirection::EForward;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLSHipDirection UOLSLocomotionBPLibrary::GetOppositeHipDirection(EOLSHipDirection currentHipDirection)
|
|
|
|
{
|
|
|
|
return (currentHipDirection == EOLSHipDirection::EForward ? EOLSHipDirection::EBackward : EOLSHipDirection::EForward);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UOLSLocomotionBPLibrary::TryLinkAnimLayer(USkeletalMeshComponent* mesh,
|
|
|
|
TSubclassOf<UAnimInstance> animClass,
|
|
|
|
FName groupName,
|
|
|
|
bool shouldUnlinkGroupIfInvalid)
|
|
|
|
{
|
|
|
|
if (!animClass->IsValidLowLevelFast())
|
|
|
|
{
|
|
|
|
if (shouldUnlinkGroupIfInvalid)
|
|
|
|
{
|
|
|
|
if (const TObjectPtr<UAnimInstance> linkedAnimInstance = mesh->GetLinkedAnimLayerInstanceByGroup(groupName))
|
|
|
|
{
|
|
|
|
mesh->UnlinkAnimClassLayers(linkedAnimInstance.GetClass());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh->LinkAnimClassLayers(animClass);
|
|
|
|
}
|