blaster/Source/Blaster/Character/BlasterAnimInstance.cpp

52 lines
1.8 KiB
C++
Raw Normal View History

2022-04-28 13:30:18 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "BlasterAnimInstance.h"
#include "BlasterCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
2022-05-02 13:40:33 +00:00
#include "Kismet/KismetMathLibrary.h"
2022-04-28 13:30:18 +00:00
void UBlasterAnimInstance::NativeInitializeAnimation()
{
Super::NativeInitializeAnimation();
BlasterCharacter = Cast<ABlasterCharacter>(TryGetPawnOwner());
}
void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
if (BlasterCharacter == nullptr)
{
BlasterCharacter = Cast<ABlasterCharacter>(TryGetPawnOwner());
}
if (BlasterCharacter == nullptr) return;
FVector Velocity = BlasterCharacter->GetVelocity();
Velocity.Z = 0.f;
Speed = Velocity.Size();
bIsInAir = BlasterCharacter->GetCharacterMovement()->IsFalling();
bIsAccelerating = BlasterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0.f;
2022-04-30 14:48:34 +00:00
bWeaponEquipped = BlasterCharacter->IsWeaponEquipped();
2022-04-30 15:10:07 +00:00
bIsCrouched = BlasterCharacter->bIsCrouched;
2022-04-30 15:38:03 +00:00
bAiming = BlasterCharacter->IsAiming();
2022-05-02 13:40:33 +00:00
// Offset Yaw for Strafing
FRotator AimRotation = BlasterCharacter->GetBaseAimRotation();
FRotator MovementRotation = UKismetMathLibrary::MakeRotFromX(BlasterCharacter->GetVelocity());
FRotator DeltaRot = UKismetMathLibrary::NormalizedDeltaRotator(MovementRotation, AimRotation);
DeltaRotation = FMath::RInterpTo(DeltaRotation, DeltaRot, DeltaSeconds, 6.f);
YawOffset = DeltaRotation.Yaw;
CharacterRotationLastFrame = CharacterRotation;
CharacterRotation = BlasterCharacter->GetActorRotation();
const FRotator Delta = UKismetMathLibrary::NormalizedDeltaRotator(CharacterRotation, CharacterRotationLastFrame);
const float Target = Delta.Yaw / DeltaSeconds;
const float Interp = FMath::FInterpTo(Lean, Target, DeltaSeconds, 6.f);
Lean = FMath::Clamp(Interp, -90.f, 90.f);
2022-04-28 13:30:18 +00:00
}