56 - Applying Aim Offsets
This commit is contained in:
parent
cf45d21cf8
commit
534cdfe902
Binary file not shown.
|
@ -48,4 +48,7 @@ void UBlasterAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
|
||||||
const float Target = Delta.Yaw / DeltaSeconds;
|
const float Target = Delta.Yaw / DeltaSeconds;
|
||||||
const float Interp = FMath::FInterpTo(Lean, Target, DeltaSeconds, 6.f);
|
const float Interp = FMath::FInterpTo(Lean, Target, DeltaSeconds, 6.f);
|
||||||
Lean = FMath::Clamp(Interp, -90.f, 90.f);
|
Lean = FMath::Clamp(Interp, -90.f, 90.f);
|
||||||
|
|
||||||
|
AO_Yaw = BlasterCharacter->GetAO_Yaw();
|
||||||
|
AO_Pitch = BlasterCharacter->GetAO_Pitch();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,12 @@ private:
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
|
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
|
||||||
float Lean;
|
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 CharacterRotationLastFrame;
|
||||||
FRotator CharacterRotation;
|
FRotator CharacterRotation;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "Components/WidgetComponent.h"
|
#include "Components/WidgetComponent.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "GameFramework/SpringArmComponent.h"
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
#include "Net/UnrealNetwork.h"
|
#include "Net/UnrealNetwork.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +66,8 @@ void ABlasterCharacter::BeginPlay()
|
||||||
void ABlasterCharacter::Tick(float DeltaTime)
|
void ABlasterCharacter::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
AimOffset(DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
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()
|
void ABlasterCharacter::ServerEquipButtonPressed_Implementation()
|
||||||
{
|
{
|
||||||
EquipButtonPressed();
|
EquipButtonPressed();
|
||||||
|
|
|
@ -29,6 +29,7 @@ protected:
|
||||||
void CrouchButtonPressed();
|
void CrouchButtonPressed();
|
||||||
void AimButtonPressed();
|
void AimButtonPressed();
|
||||||
void AimButtonReleased();
|
void AimButtonReleased();
|
||||||
|
void AimOffset(float DeltaTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleAnywhere, Category="Camera")
|
UPROPERTY(VisibleAnywhere, Category="Camera")
|
||||||
|
@ -51,8 +52,14 @@ private:
|
||||||
|
|
||||||
UFUNCTION(Server, Reliable)
|
UFUNCTION(Server, Reliable)
|
||||||
void ServerEquipButtonPressed();
|
void ServerEquipButtonPressed();
|
||||||
|
|
||||||
|
float AO_Yaw;
|
||||||
|
float AO_Pitch;
|
||||||
|
FRotator StartingAimRotation;
|
||||||
public:
|
public:
|
||||||
void SetOverlappingWeapon(AWeapon* Weapon);
|
void SetOverlappingWeapon(AWeapon* Weapon);
|
||||||
bool IsWeaponEquipped();
|
bool IsWeaponEquipped();
|
||||||
bool IsAiming();
|
bool IsAiming();
|
||||||
|
FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; };
|
||||||
|
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue