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-05-12 13:37:49 +00:00
|
|
|
#include "Blaster/Weapon/Weapon.h"
|
|
|
|
#include "Blaster/Types/CombatState.h"
|
2022-04-28 13:30:18 +00:00
|
|
|
|
|
|
|
void UBlasterAnimInstance::NativeInitializeAnimation()
|
|
|
|
{
|
|
|
|
Super::NativeInitializeAnimation();
|
|
|
|
|
|
|
|
BlasterCharacter = Cast<ABlasterCharacter>(TryGetPawnOwner());
|
|
|
|
}
|
|
|
|
|
2022-05-12 13:37:49 +00:00
|
|
|
void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaTime)
|
2022-04-28 13:30:18 +00:00
|
|
|
{
|
2022-05-12 13:37:49 +00:00
|
|
|
Super::NativeUpdateAnimation(DeltaTime);
|
2022-04-28 13:30:18 +00:00
|
|
|
|
|
|
|
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();
|
2022-05-12 13:37:49 +00:00
|
|
|
bIsAccelerating = BlasterCharacter->GetCharacterMovement()->GetCurrentAcceleration().Size() > 0.f ? true : false;
|
2022-04-30 14:48:34 +00:00
|
|
|
bWeaponEquipped = BlasterCharacter->IsWeaponEquipped();
|
2022-05-29 13:28:58 +00:00
|
|
|
EquippedWeapon = BlasterCharacter->GetEquippedWeapon();
|
2022-04-30 15:10:07 +00:00
|
|
|
bIsCrouched = BlasterCharacter->bIsCrouched;
|
2022-04-30 15:38:03 +00:00
|
|
|
bAiming = BlasterCharacter->IsAiming();
|
2022-05-04 09:28:00 +00:00
|
|
|
TurningInPlace = BlasterCharacter->GetTurningInPlace();
|
2022-05-06 10:43:18 +00:00
|
|
|
bRotateRootBone = BlasterCharacter->ShouldRotateRootBone();
|
2022-05-07 17:10:32 +00:00
|
|
|
bEliminated = BlasterCharacter->IsEliminated();
|
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);
|
2022-05-12 13:37:49 +00:00
|
|
|
DeltaRotation = FMath::RInterpTo(DeltaRotation, DeltaRot, DeltaTime, 6.f);
|
2022-05-02 13:40:33 +00:00
|
|
|
YawOffset = DeltaRotation.Yaw;
|
2022-05-12 13:37:49 +00:00
|
|
|
|
2022-05-02 13:40:33 +00:00
|
|
|
CharacterRotationLastFrame = CharacterRotation;
|
|
|
|
CharacterRotation = BlasterCharacter->GetActorRotation();
|
|
|
|
const FRotator Delta = UKismetMathLibrary::NormalizedDeltaRotator(CharacterRotation, CharacterRotationLastFrame);
|
2022-05-12 13:37:49 +00:00
|
|
|
const float Target = Delta.Yaw / DeltaTime;
|
|
|
|
const float Interp = FMath::FInterpTo(Lean, Target, DeltaTime, 6.f);
|
2022-05-02 13:40:33 +00:00
|
|
|
Lean = FMath::Clamp(Interp, -90.f, 90.f);
|
2022-05-03 21:14:04 +00:00
|
|
|
|
|
|
|
AO_Yaw = BlasterCharacter->GetAO_Yaw();
|
|
|
|
AO_Pitch = BlasterCharacter->GetAO_Pitch();
|
2022-05-12 13:37:49 +00:00
|
|
|
|
2022-05-03 22:43:10 +00:00
|
|
|
if (bWeaponEquipped && EquippedWeapon && EquippedWeapon->GetWeaponMesh() && BlasterCharacter->GetMesh())
|
|
|
|
{
|
2022-05-12 13:37:49 +00:00
|
|
|
LeftHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("LeftHandSocket"), ERelativeTransformSpace::RTS_World);
|
2022-05-03 22:43:10 +00:00
|
|
|
FVector OutPosition;
|
|
|
|
FRotator OutRotation;
|
|
|
|
BlasterCharacter->GetMesh()->TransformToBoneSpace(FName("hand_r"), LeftHandTransform.GetLocation(), FRotator::ZeroRotator, OutPosition, OutRotation);
|
|
|
|
LeftHandTransform.SetLocation(OutPosition);
|
|
|
|
LeftHandTransform.SetRotation(FQuat(OutRotation));
|
2022-05-05 18:14:17 +00:00
|
|
|
|
|
|
|
if (BlasterCharacter->IsLocallyControlled())
|
|
|
|
{
|
|
|
|
bLocallyControlled = true;
|
2022-05-12 13:37:49 +00:00
|
|
|
FTransform RightHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("Hand_R"), ERelativeTransformSpace::RTS_World);
|
2022-05-05 20:46:35 +00:00
|
|
|
FRotator LookAtRotation = UKismetMathLibrary::FindLookAtRotation(RightHandTransform.GetLocation(), RightHandTransform.GetLocation() + (RightHandTransform.GetLocation() - BlasterCharacter->GetHitTarget()));
|
2022-05-12 13:37:49 +00:00
|
|
|
RightHandRotation = FMath::RInterpTo(RightHandRotation, LookAtRotation, DeltaTime, 30.f);
|
2022-05-05 18:14:17 +00:00
|
|
|
}
|
2022-05-03 22:43:10 +00:00
|
|
|
}
|
2022-05-09 21:16:55 +00:00
|
|
|
|
2022-05-21 10:13:03 +00:00
|
|
|
bUseFABRIK = BlasterCharacter->GetCombatState() == ECombatState::ECS_Unoccupied;
|
2022-05-28 10:16:32 +00:00
|
|
|
bool bFABRIKOverride = BlasterCharacter->IsLocallyControlled() &&
|
|
|
|
BlasterCharacter->GetCombatState() != ECombatState::ECS_ThrowingGrenade &&
|
|
|
|
BlasterCharacter->bFinishedSwapping;
|
|
|
|
|
|
|
|
if (bFABRIKOverride)
|
2022-05-26 15:09:25 +00:00
|
|
|
{
|
|
|
|
bUseFABRIK = !BlasterCharacter->IsLocallyReloading();
|
|
|
|
}
|
2022-05-21 10:13:03 +00:00
|
|
|
bUseAimOffsets = BlasterCharacter->GetCombatState() == ECombatState::ECS_Unoccupied && !BlasterCharacter->GetDisableGameplay();
|
|
|
|
bTransformRightHand = BlasterCharacter->GetCombatState() == ECombatState::ECS_Unoccupied && !BlasterCharacter->GetDisableGameplay();
|
2022-04-28 13:30:18 +00:00
|
|
|
}
|