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);
|
||||
bool IsWeaponEquipped();
|
||||
bool IsAiming();
|
||||
FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; };
|
||||
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; };
|
||||
FORCEINLINE float GetAO_Yaw() const { return AO_Yaw; }
|
||||
FORCEINLINE float GetAO_Pitch() const { return AO_Pitch; }
|
||||
AWeapon* GetEquippedWeapon();
|
||||
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; };
|
||||
FORCEINLINE ETurningInPlace GetTurningInPlace() const { return TurningInPlace; }
|
||||
FVector GetHitTarget() const;
|
||||
FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; }
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Blaster/HUD/BlasterHUD.h"
|
||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||
#include "Blaster/Weapon/Weapon.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Engine/SkeletalMeshSocket.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
@ -35,6 +36,12 @@ void UCombatComponent::BeginPlay()
|
|||
if (Character)
|
||||
{
|
||||
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);
|
||||
|
||||
SetHUDCrosshairs(DeltaTime);
|
||||
|
||||
if (Character && Character->IsLocallyControlled())
|
||||
{
|
||||
FHitResult HitResult;
|
||||
TraceUnderCrosshairs(HitResult);
|
||||
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)
|
||||
{
|
||||
bAiming = bIsAiming;
|
||||
|
|
|
@ -63,12 +63,24 @@ private:
|
|||
|
||||
bool bFireButtonPressed;
|
||||
|
||||
/*
|
||||
* HUD and Crosshairs
|
||||
*/
|
||||
|
||||
//HUD and Crosshairs
|
||||
float CrosshairVelocityFactor;
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -44,6 +44,13 @@ public:
|
|||
UPROPERTY(EditAnywhere, Category= Crosshairs)
|
||||
class UTexture2D* CrosshairsBottom;
|
||||
|
||||
// Zoom FOV while aiming
|
||||
UPROPERTY(EditAnywhere)
|
||||
float ZoomedFOV = 30.f;
|
||||
|
||||
UPROPERTY(EditAnywhere)
|
||||
float ZoomInterpSpeed = 20.f;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
@ -92,4 +99,7 @@ public:
|
|||
void SetWeaponState(EWeaponState State);
|
||||
FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }
|
||||
FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; };
|
||||
FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; };
|
||||
FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; };
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue