253 lines
8.1 KiB
C++
253 lines
8.1 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "GameFramework/Character.h"
|
|
#include "ShooterCharacter.generated.h"
|
|
|
|
class USpringArmComponent;
|
|
class UCameraComponent;
|
|
class USoundCue;
|
|
class UParticleSystem;
|
|
class UAnimMontage;
|
|
class AItem;
|
|
|
|
UCLASS()
|
|
class SHOOTER_API AShooterCharacter : public ACharacter
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
// Sets default values for this character's properties
|
|
AShooterCharacter();
|
|
|
|
protected:
|
|
// Called when the game starts or when spawned
|
|
virtual void BeginPlay() override;
|
|
|
|
/* Called for forwards/backwards input */
|
|
void MoveForward(float Value);
|
|
|
|
/* Called for side to side input */
|
|
void MoveRight(float Value);
|
|
|
|
/**
|
|
* Called via input to turn at a given rate.
|
|
* @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired rate
|
|
*/
|
|
void TurnAtRate(float Rate);
|
|
|
|
/**
|
|
* Called via input to look up/down at a given rate.
|
|
* @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired rate
|
|
*/
|
|
void LookUpAtRate(float Rate);
|
|
|
|
/**
|
|
* Rotate controller based on mouse X movement
|
|
*
|
|
* @param Value The input value from mouse movement
|
|
*/
|
|
void Turn(float Value);
|
|
|
|
/**
|
|
* Rotate controller based on mouse Y movement
|
|
*
|
|
* @param Value The input value from mouse movement
|
|
*/
|
|
void LookUp(float Value);
|
|
|
|
/**
|
|
* Called when the Fire button is pressed
|
|
*/
|
|
void FireWeapon();
|
|
|
|
bool GetBeamEndLocation(const FVector& MuzzleSocketLocation, FVector& OutBeamLocation);
|
|
|
|
/* Set bAiming to true or false with button press */
|
|
void AimingButtonPressed();
|
|
void AimingButtonReleased();
|
|
|
|
void CameraInterpZoom(float DeltaTime);
|
|
|
|
/* Set BaseTurnRate and BaseLookUpRate based on aiming */
|
|
void SetLookRates();
|
|
|
|
void CalculateCrosshairSpread(float DeltaTime);
|
|
|
|
void StartCrosshairBulletFire();
|
|
|
|
UFUNCTION()
|
|
void FinishCrosshairBulletFire();
|
|
|
|
void FireButtonPressed();
|
|
void FireButtonReleased();
|
|
|
|
void StartFireTimer();
|
|
|
|
UFUNCTION()
|
|
void AutoFireReset();
|
|
|
|
/** Line trace for items under the crosshairs */
|
|
bool TraceUnderCrosshairs(FHitResult& OutHitResult, FVector& OutHitLocation);
|
|
|
|
/* Trace for items if OverlappedItemCount > 0 */
|
|
void TraceForItems();
|
|
|
|
void SetItemPickupWidgetVisibility(AItem* Item, bool visibility);
|
|
|
|
public:
|
|
// Called every frame
|
|
virtual void Tick(float DeltaTime) override;
|
|
|
|
// Called to bind functionality to input
|
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
|
|
|
private:
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
USpringArmComponent* CameraBoom;
|
|
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
UCameraComponent* FollowCamera;
|
|
|
|
/* Base turn rate, in deg/sec. Other scaling may affect final rate */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
float BaseTurnRate;
|
|
|
|
/* Base look up/down rate, in deg/sec. Other scaling may affect final rate */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
float BaseLookUpRate;
|
|
|
|
/* Turn rate while not aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
float HipTurnRate;
|
|
|
|
/* Look up rate while not aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
float HipLookUpRate;
|
|
|
|
/* Turn rate when aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
float AimingTurnRate;
|
|
|
|
/* Look up rate when aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true))
|
|
float AimingLookUpRate;
|
|
|
|
/* Scale factor for mouse look sensitivity. Turn rate when not aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true),
|
|
meta = (ClampMin = 0.0, ClampMax = 1.0, UIMin = 0.0, UIMax = 1.0))
|
|
float MouseHipTurnRate;
|
|
|
|
/* Scale factor for mouse look sensitivity. Look up rate when not aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true),
|
|
meta = (ClampMin = 0.0, ClampMax = 1.0, UIMin = 0.0, UIMax = 1.0))
|
|
float MouseHipLookUpRate;
|
|
|
|
/* Scale factor for mouse look sensitivity. Turn rate when aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true),
|
|
meta = (ClampMin = 0.0, ClampMax = 1.0, UIMin = 0.0, UIMax = 1.0))
|
|
float MouseAimingTurnRate;
|
|
|
|
/* Scale factor for mouse look sensitivity. Look up rate when aiming */
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = true),
|
|
meta = (ClampMin = 0.0, ClampMax = 1.0, UIMin = 0.0, UIMax = 1.0))
|
|
float MouseAimingLookUpRate;
|
|
|
|
/* Randomized gunshot sound cue*/
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
USoundCue* FireSound;
|
|
|
|
/* Flash spawned at BarrelSocket */
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
UParticleSystem* MuzzleFlash;
|
|
|
|
/* Montage for firing the weapon */
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
UAnimMontage* HipFireMontage;
|
|
|
|
/* Particles spawned upon bullet impact */
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
UParticleSystem* ImpactParticles;
|
|
|
|
/* Smoke trail for bullets */
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
UParticleSystem* BeamParticles;
|
|
|
|
/* True when aiming */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
bool bAiming;
|
|
|
|
/* Default camera field of view value */
|
|
float CameraDefaultFOV;
|
|
|
|
/* Field of view value when camera is zoomed in */
|
|
float CameraZoomedFOV;
|
|
|
|
/* Current field of view this frame */
|
|
float CameraCurrentFOV;
|
|
|
|
/* Interp speed for zooming when aiming */
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
|
|
float ZoomInterpSpeed;
|
|
|
|
/* Determines the spread of the crosshairs */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Crosshairs, meta = (AllowPrivateAccess = true))
|
|
float CrosshairSpreadMultiplier;
|
|
|
|
/* Velocity component for crosshairs spread */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Crosshairs, meta = (AllowPrivateAccess = true))
|
|
float CrosshairVelocityFactor;
|
|
|
|
/* In air component for crosshairs spread */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Crosshairs, meta = (AllowPrivateAccess = true))
|
|
float CrosshairInAirFactor;
|
|
|
|
/* Aim component for crosshairs spread */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Crosshairs, meta = (AllowPrivateAccess = true))
|
|
float CrosshairAimFactor;
|
|
|
|
/* Shooting component for crosshairs spread */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Crosshairs, meta = (AllowPrivateAccess = true))
|
|
float CrosshairShootingFactor;
|
|
|
|
float ShootTimeDuration;
|
|
bool bFiringBullet;
|
|
FTimerHandle CrosshairShootTimer;
|
|
|
|
bool bFireButtonPressed;
|
|
|
|
/* True when we cane fire. False when waiting for the timer */
|
|
bool bShouldFire;
|
|
|
|
/* Rate of automatic gun fire */
|
|
float AutomaticFireRate;
|
|
|
|
/* Sets a timer between gunshots */
|
|
FTimerHandle AutoFireTimer;
|
|
|
|
/* True if we should trace every frame for items */
|
|
bool bShouldTraceForItems;
|
|
|
|
/* Number of overlapped AItems */
|
|
int8 OverlappedItemCount;
|
|
|
|
public:
|
|
/* Returns CameraBoom SubObject */
|
|
FORCEINLINE USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
|
|
|
|
/* Returns FollowCamera SubObject */
|
|
FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; }
|
|
|
|
FORCEINLINE bool GetAiming() const { return bAiming; }
|
|
|
|
UFUNCTION(BlueprintCallable)
|
|
float GetCrosshairSpreadMultiplier() const;
|
|
|
|
FORCEINLINE int8 GetOverlappedItemCount() const { return OverlappedItemCount; }
|
|
|
|
/* Adds/Subtracts to/from OverlappedItemCount and updates bShouldTraceForItems */
|
|
void IncrementOverlappedItemCount(int8 Amount);
|
|
};
|