// © 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" DEFINE_LOG_CATEGORY_STATIC(LogOLSLocomotionLibrary, Verbose, All); EOLSMovementDirection UOLSLocomotionBPLibrary::SelectMovementDirectionFromAngle(float angle, const EOLSRotationMode& rotationMode, const EOLSGait& gait, const EOLSMovementDirectionBias& movementDirectionBias, const FOLSMovementDirectionThresholds& movementDirectionThreshold) { EOLSMovementDirection result = EOLSMovementDirection::EForward; if (rotationMode == EOLSRotationMode::EVelocityDirection || gait == EOLSGait::ESprint) { return result; } const bool isAngleForwardDirection = FMath::IsWithinInclusive(angle, movementDirectionThreshold.FL, movementDirectionThreshold.FR); const bool isAngleLeftDirection = FMath::IsWithinInclusive(angle, movementDirectionThreshold.BL, movementDirectionThreshold.FL); const bool isAngleRightDirection = FMath::IsWithinInclusive(angle, movementDirectionThreshold.FR, movementDirectionThreshold.BR); if (isAngleForwardDirection) { result = EOLSMovementDirection::EForward; } else if (isAngleLeftDirection) { switch (movementDirectionBias) { case EOLSMovementDirectionBias::ELeftFoot_F: result = EOLSMovementDirection::ELeftLeft; break; case EOLSMovementDirectionBias::ERightFoot_F: result = EOLSMovementDirection::ELeftRight; break; } } else if (isAngleRightDirection) { switch (movementDirectionBias) { case EOLSMovementDirectionBias::ELeftFoot_F: result = EOLSMovementDirection::ERightLeft; break; case EOLSMovementDirectionBias::ERightFoot_F: result = EOLSMovementDirection::ERightRight; break; } } else { result = EOLSMovementDirection::EBackward; } return result; } EOLSMovementDirection UOLSLocomotionBPLibrary::GetOppositeMovementDirection( const EOLSMovementDirection& currentDirection, const EOLSMovementDirectionBias& movementDirectionBias) { EOLSMovementDirection result = EOLSMovementDirection::EForward; if (currentDirection == EOLSMovementDirection::EForward) { result = EOLSMovementDirection::EBackward; } else if (currentDirection == EOLSMovementDirection::ELeftLeft || currentDirection == EOLSMovementDirection::ELeftRight) { switch (movementDirectionBias) { case EOLSMovementDirectionBias::ELeftFoot_F: result = EOLSMovementDirection::ERightLeft; break; case EOLSMovementDirectionBias::ERightFoot_F: result = EOLSMovementDirection::ERightRight; break; } } else if (currentDirection == EOLSMovementDirection::ERightLeft || currentDirection == EOLSMovementDirection::ERightRight) { switch (movementDirectionBias) { case EOLSMovementDirectionBias::ELeftFoot_F: result = EOLSMovementDirection::ELeftLeft; break; case EOLSMovementDirectionBias::ERightFoot_F: result = EOLSMovementDirection::ELeftRight; break; } } else { result = EOLSMovementDirection::EBackward; } return result; } void UOLSLocomotionBPLibrary::TryLinkAnimLayer(USkeletalMeshComponent* mesh, TSubclassOf animClass, FName groupName, bool shouldUnlinkGroupIfInvalid) { if (!animClass->IsValidLowLevelFast()) { if (shouldUnlinkGroupIfInvalid) { if (const TObjectPtr linkedAnimInstance = mesh->GetLinkedAnimLayerInstanceByGroup(groupName)) { mesh->UnlinkAnimClassLayers(linkedAnimInstance.GetClass()); } } return; } mesh->LinkAnimClassLayers(animClass); }