AO회전값에 보간을 줘서 좀더 자연스럽고 부드럽게 표현이 가능하다.
회전과 액터의 차를 정규화 시켜서 회전값을 보간 - 이후 각도를 제한 시켜서. 사용 (안에 Deltatime이 들어간다)
Animinstance.cpp
#include "CAnimInstance.h"
#include "Global.h"
#include "GameFramework/Character.h"
#include "05_TPS/IRifle.h"
void UCAnimInstance::NativeBeginPlay()
{
Super::NativeBeginPlay();
OwnerCharacter = Cast<ACharacter>(TryGetPawnOwner());
}
void UCAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
if (OwnerCharacter == nullptr) return;
Speed = OwnerCharacter->GetVelocity().Size2D();
FRotator current = FRotator(Pitch, 0, 0);
FRotator A = OwnerCharacter->GetControlRotation();
FRotator B = OwnerCharacter->GetActorRotation();
FRotator target = UKismetMathLibrary::NormalizedDeltaRotator(A, B);
Pitch = UKismetMathLibrary::RInterpTo(current, target, DeltaSeconds, 0).Pitch;
Pitch = UKismetMathLibrary::ClampAngle(Pitch, -90, 90);
//Pitch = OwnerCharacter->GetBaseAimRotation().Pitch;
IIRifle* rifle = Cast<IIRifle>(OwnerCharacter);
FRotator forward = OwnerCharacter->GetControlRotation();
if (!!rifle)
{
bEquipped = rifle->IsEquipped_Rifle();
bAiming = rifle ->IsAiming_Rifle();
if (bEquipped)
forward = OwnerCharacter->GetActorRotation();
}
Direction = CalculateDirection(OwnerCharacter->GetVelocity(), forward);
}
FRotator A = OwnerCharacter->GetControlRotation();
FRotator B = OwnerCharacter->GetActorRotation();
FRotator target = UKismetMathLibrary::NormalizedDeltaRotator(A, B);
NormalizedDeltaRotator : A 회전값하고 B회전값 = 회전값 차 이것을 정규화 시킴. (이 회전 값에 얼마만큼 갈지 정해서 편하게 사용하는 방법?)
FRotator UKismetMathLibrary::**NormalizedDeltaRotator**(FRotator A, FRotator B)
{
FRotator Delta = A - B;
Delta.Normalize();
return Delta;
}
Rifle 회전 및 위치
다음시간. 1인칭 시점.