61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
// Project Lab - NHTV Igad
|
|
|
|
#include "UnrealProject.h"
|
|
#include "MinionAnimInstance.h"
|
|
|
|
UMinionAnimInstance::UMinionAnimInstance(const FObjectInitializer& init)
|
|
: Super(init)
|
|
{
|
|
m_animationState = EMinionAnimState::MAS_Idle;
|
|
}
|
|
|
|
void UMinionAnimInstance::NativeInitializeAnimation()
|
|
{
|
|
Super::NativeInitializeAnimation();
|
|
m_animationState = EMinionAnimState::MAS_Idle;
|
|
}
|
|
|
|
void UMinionAnimInstance::NativeUpdateAnimation(float deltaSeconds)
|
|
{
|
|
Super::NativeUpdateAnimation(deltaSeconds);
|
|
|
|
APawn* ownerPawn = TryGetPawnOwner();
|
|
|
|
if (IsValid(ownerPawn))
|
|
{
|
|
const FVector velocity = ownerPawn->GetVelocity();
|
|
const FVector forward = ownerPawn->GetActorForwardVector().GetSafeNormal2D();
|
|
|
|
m_movementSpeed = velocity.Size();
|
|
|
|
float angleBetween = FMath::FindDeltaAngle(forward.HeadingAngle(), velocity.GetSafeNormal2D().HeadingAngle());
|
|
m_movementDirectionRelative = FVector(cos(angleBetween), sin(angleBetween), 0);
|
|
}
|
|
}
|
|
|
|
EMinionAnimState UMinionAnimInstance::GetAnimationState()
|
|
{
|
|
return m_animationState;
|
|
}
|
|
|
|
bool UMinionAnimInstance::IsInAnimationState(const EMinionAnimState minionStateCheck)
|
|
{
|
|
return (m_animationState == minionStateCheck);
|
|
}
|
|
|
|
void UMinionAnimInstance::ChangeAnimationStateTo(EMinionAnimState newState)
|
|
{
|
|
m_animationState = newState;
|
|
}
|
|
|
|
void UMinionAnimInstance::BPChangeAnimationStateTo(EMinionAnimState newState)
|
|
{
|
|
m_animationState = newState;
|
|
OnAnimationStateChanged.Broadcast(newState);
|
|
}
|
|
|
|
void UMinionAnimInstance::PlaySpecificAnimationByInt(int32 animationToPlay)
|
|
{
|
|
m_specificAnimationIndex = animationToPlay;
|
|
ChangeAnimationStateTo(EMinionAnimState::MAS_Specific);
|
|
} |