super-duper-spoon/Source/Shooter/ShooterAnimInstance.cpp

48 lines
1.4 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "ShooterAnimInstance.h"
#include "ShooterCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Kismet/KismetMathLibrary.h"
void UShooterAnimInstance::UpdateAnimationProperties(float DeltaTime)
{
if (ShooterCharacter)
ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
if (ShooterCharacter)
{
// Get the speed of the character from velocity
FVector Velocity{ ShooterCharacter->GetVelocity() };
Velocity.Z = 0;
Speed = Velocity.Size();
// Is the character in the air
bIsInAir = ShooterCharacter->GetCharacterMovement()->IsFalling();
// Is the character accelerating
bIsAccelerating = ShooterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0;
FRotator AimRotation = ShooterCharacter->GetBaseAimRotation();
FRotator MovementRotation = UKismetMathLibrary::MakeRotFromX(ShooterCharacter->GetVelocity());
MovementOffsetYaw = UKismetMathLibrary::NormalizedDeltaRotator(MovementRotation, AimRotation).Yaw;
if (ShooterCharacter->GetVelocity().Size() > 0)
{
LastMovementOffsetYaw = MovementOffsetYaw;
}
bAiming = ShooterCharacter->GetAiming();
}
}
void UShooterAnimInstance::NativeInitializeAnimation()
{
Super::NativeInitializeAnimation();
ShooterCharacter = Cast<AShooterCharacter>(TryGetPawnOwner());
}