84 - Zoom While Aiming
This commit is contained in:
parent
ad7af7454b
commit
38473505f5
Binary file not shown.
Binary file not shown.
|
@ -72,9 +72,10 @@ 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_Yaw() const { return AO_Yaw; }
|
||||||
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; };
|
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; }
|
||||||
AWeapon* GetEquippedWeapon();
|
AWeapon* GetEquippedWeapon();
|
||||||
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; };
|
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; }
|
||||||
FVector GetHitTarget() const;
|
FVector GetHitTarget() const;
|
||||||
|
FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "Blaster/HUD/BlasterHUD.h"
|
#include "Blaster/HUD/BlasterHUD.h"
|
||||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||||
#include "Blaster/Weapon/Weapon.h"
|
#include "Blaster/Weapon/Weapon.h"
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Engine/SkeletalMeshSocket.h"
|
#include "Engine/SkeletalMeshSocket.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
@ -35,6 +36,12 @@ void UCombatComponent::BeginPlay()
|
||||||
if (Character)
|
if (Character)
|
||||||
{
|
{
|
||||||
Character->GetCharacterMovement()->MaxWalkSpeed = BaseWalkSpeed;
|
Character->GetCharacterMovement()->MaxWalkSpeed = BaseWalkSpeed;
|
||||||
|
|
||||||
|
if (Character->GetFollowCamera())
|
||||||
|
{
|
||||||
|
DefaultFOV = Character->GetFollowCamera()->FieldOfView;
|
||||||
|
CurrentFOV = DefaultFOV;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,13 +49,14 @@ void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
|
||||||
{
|
{
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
SetHUDCrosshairs(DeltaTime);
|
|
||||||
|
|
||||||
if (Character && Character->IsLocallyControlled())
|
if (Character && Character->IsLocallyControlled())
|
||||||
{
|
{
|
||||||
FHitResult HitResult;
|
FHitResult HitResult;
|
||||||
TraceUnderCrosshairs(HitResult);
|
TraceUnderCrosshairs(HitResult);
|
||||||
HitTarget = HitResult.ImpactPoint;
|
HitTarget = HitResult.ImpactPoint;
|
||||||
|
|
||||||
|
SetHUDCrosshairs(DeltaTime);
|
||||||
|
InterpFOV(DeltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +113,24 @@ void UCombatComponent::SetHUDCrosshairs(float DeltaTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UCombatComponent::InterpFOV(float DeltaTime)
|
||||||
|
{
|
||||||
|
if (EquippedWeapon == nullptr) return;
|
||||||
|
|
||||||
|
if (bAiming)
|
||||||
|
{
|
||||||
|
CurrentFOV = FMath::FInterpTo(CurrentFOV, EquippedWeapon->GetZoomedFOV(), DeltaTime, EquippedWeapon->GetZoomInterpSpeed());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CurrentFOV = FMath::FInterpTo(CurrentFOV, DefaultFOV, DeltaTime, ZoomInterpSpeed);
|
||||||
|
}
|
||||||
|
if (Character && Character->GetFollowCamera())
|
||||||
|
{
|
||||||
|
Character->GetFollowCamera()->SetFieldOfView(CurrentFOV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UCombatComponent::SetAiming(bool bIsAiming)
|
void UCombatComponent::SetAiming(bool bIsAiming)
|
||||||
{
|
{
|
||||||
bAiming = bIsAiming;
|
bAiming = bIsAiming;
|
||||||
|
|
|
@ -63,12 +63,24 @@ private:
|
||||||
|
|
||||||
bool bFireButtonPressed;
|
bool bFireButtonPressed;
|
||||||
|
|
||||||
/*
|
//HUD and Crosshairs
|
||||||
* HUD and Crosshairs
|
|
||||||
*/
|
|
||||||
|
|
||||||
float CrosshairVelocityFactor;
|
float CrosshairVelocityFactor;
|
||||||
float CrosshairInAirFactor;
|
float CrosshairInAirFactor;
|
||||||
|
|
||||||
|
// Aiming and FOV
|
||||||
|
|
||||||
|
// Field of view when not aiming; set to the camera's base FOV in BeginPlay
|
||||||
|
float DefaultFOV;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = Combat)
|
||||||
|
float ZoomedFOV = 30.f;
|
||||||
|
|
||||||
|
float CurrentFOV;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = Combat)
|
||||||
|
float ZoomInterpSpeed = 20.f;
|
||||||
|
|
||||||
|
void InterpFOV(float DeltaTime);
|
||||||
|
|
||||||
FVector HitTarget;
|
FVector HitTarget;
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,6 +44,13 @@ public:
|
||||||
UPROPERTY(EditAnywhere, Category= Crosshairs)
|
UPROPERTY(EditAnywhere, Category= Crosshairs)
|
||||||
class UTexture2D* CrosshairsBottom;
|
class UTexture2D* CrosshairsBottom;
|
||||||
|
|
||||||
|
// Zoom FOV while aiming
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float ZoomedFOV = 30.f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float ZoomInterpSpeed = 20.f;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
@ -92,4 +99,7 @@ public:
|
||||||
void SetWeaponState(EWeaponState State);
|
void SetWeaponState(EWeaponState State);
|
||||||
FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }
|
FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }
|
||||||
FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; };
|
FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; };
|
||||||
|
FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; };
|
||||||
|
FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue