56 - Applying Aim Offsets

This commit is contained in:
Kingsmedia 2022-05-03 23:14:04 +02:00
parent cf45d21cf8
commit 534cdfe902
5 changed files with 45 additions and 0 deletions

View File

@ -48,4 +48,7 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
const float Target = Delta.Yaw / DeltaSeconds;
const float Interp = FMath::FInterpTo(Lean, Target, DeltaSeconds, 6.f);
Lean = FMath::Clamp(Interp, -90.f, 90.f);
AO_Yaw = BlasterCharacter->GetAO_Yaw();
AO_Pitch = BlasterCharacter->GetAO_Pitch();
}

View File

@ -47,6 +47,12 @@ private:
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
float Lean;
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
float AO_Yaw;
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
float AO_Pitch;
FRotator CharacterRotationLastFrame;
FRotator CharacterRotation;

View File

@ -10,6 +10,7 @@
#include "Components/WidgetComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "Net/UnrealNetwork.h"
@ -65,6 +66,8 @@ void ABlasterCharacter::BeginPlay()
void ABlasterCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
AimOffset(DeltaTime);
}
void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
@ -158,6 +161,32 @@ void ABlasterCharacter::AimButtonReleased()
}
}
void ABlasterCharacter::AimOffset(float DeltaTime)
{
if (Combat && Combat->EquippedWeapon == nullptr) return;
FVector Velocity = GetVelocity();
Velocity.Z = 0.f;
float Speed = Velocity.Size();
bool bIsInAir = GetCharacterMovement()->IsFalling();
if (Speed == 0.f && !bIsInAir) // Standing still, not jumping
{
FRotator CurrentAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f);
FRotator DeltaAimRotation = UKismetMathLibrary::NormalizedDeltaRotator(CurrentAimRotation, StartingAimRotation);
AO_Yaw = DeltaAimRotation.Yaw;
bUseControllerRotationYaw = false;
}
if (Speed > 0.f || bIsInAir) // Running or jumping
{
StartingAimRotation = FRotator(0.f, GetBaseAimRotation().Yaw, 0.f);
AO_Yaw = 0.f;
bUseControllerRotationYaw = true;
}
AO_Pitch = GetBaseAimRotation().Pitch;
}
void ABlasterCharacter::ServerEquipButtonPressed_Implementation()
{
EquipButtonPressed();

View File

@ -29,6 +29,7 @@ protected:
void CrouchButtonPressed();
void AimButtonPressed();
void AimButtonReleased();
void AimOffset(float DeltaTime);
private:
UPROPERTY(VisibleAnywhere, Category="Camera")
@ -51,8 +52,14 @@ private:
UFUNCTION(Server, Reliable)
void ServerEquipButtonPressed();
float AO_Yaw;
float AO_Pitch;
FRotator StartingAimRotation;
public:
void SetOverlappingWeapon(AWeapon* Weapon);
bool IsWeaponEquipped();
bool IsAiming();
FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; };
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; };
};