feat: slower movement when aiming
When player aiming, sprint isn't possible and walk speed is reduced to 70%
This commit is contained in:
parent
0b52fe2b4f
commit
c372d9e8d5
|
|
@ -191,12 +191,18 @@ void UShootingComponent::StartAiming()
|
||||||
{
|
{
|
||||||
if (IsValid(CurrentGun))
|
if (IsValid(CurrentGun))
|
||||||
{
|
{
|
||||||
|
PlayerCharacter->bIsAimingMode = true;
|
||||||
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed * AimingMoveSpeedScale;
|
||||||
|
|
||||||
TargetFOV = CurrentGun->AimingFOV;
|
TargetFOV = CurrentGun->AimingFOV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UShootingComponent::StopAiming()
|
void UShootingComponent::StopAiming()
|
||||||
{
|
{
|
||||||
|
PlayerCharacter->bIsAimingMode = false;
|
||||||
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
||||||
|
|
||||||
TargetFOV = DefaultFOV;
|
TargetFOV = DefaultFOV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,6 +212,6 @@ void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FAc
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
float CurrentFOV = CameraManager->GetFOVAngle();
|
float CurrentFOV = CameraManager->GetFOVAngle();
|
||||||
float NewFOV = FMath::FInterpTo(CurrentFOV, TargetFOV, DeltaTime, AimingSpeed);
|
float NewFOV = FMath::FInterpTo(CurrentFOV, TargetFOV, DeltaTime, AimingAnimationSpeed);
|
||||||
CameraManager->SetFOV(NewFOV);
|
CameraManager->SetFOV(NewFOV);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,16 +143,22 @@ void AExoPlayerController::PlayerStopCrouch()
|
||||||
|
|
||||||
void AExoPlayerController::PlayerStartSprint()
|
void AExoPlayerController::PlayerStartSprint()
|
||||||
{
|
{
|
||||||
UE_LOG(LogTemp, Display, TEXT("Start sprint"));
|
if (!PlayerCharacter->bIsAimingMode)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Start sprint"));
|
||||||
|
|
||||||
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SprintSpeed;
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SprintSpeed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerStopSprint()
|
void AExoPlayerController::PlayerStopSprint()
|
||||||
{
|
{
|
||||||
UE_LOG(LogTemp, Display, TEXT("Stop sprint"));
|
if (!PlayerCharacter->bIsAimingMode)
|
||||||
|
{
|
||||||
|
UE_LOG(LogTemp, Display, TEXT("Stop sprint"));
|
||||||
|
|
||||||
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerShoot()
|
void AExoPlayerController::PlayerShoot()
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
#include <Characters/ExoPlayerCharacter.h>
|
#include <Characters/ExoPlayerCharacter.h>
|
||||||
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
#include <Items/GunBase.h>
|
#include <Items/GunBase.h>
|
||||||
#include "Interfaces/Damageable.h"
|
#include "Interfaces/Damageable.h"
|
||||||
#include "ShootingComponent.generated.h"
|
#include "ShootingComponent.generated.h"
|
||||||
|
|
@ -63,8 +64,11 @@ public:
|
||||||
UFUNCTION(Category = "Shooting")
|
UFUNCTION(Category = "Shooting")
|
||||||
void StopAiming();
|
void StopAiming();
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Aiming")
|
||||||
float AimingSpeed = 30.0f;
|
float AimingAnimationSpeed = 30.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Aiming")
|
||||||
|
float AimingMoveSpeedScale = 0.70f;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting")
|
||||||
float DropGunRange = 20.0f;
|
float DropGunRange = 20.0f;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ public:
|
||||||
UPROPERTY(EditAnywhere, Category = "Movement Properties")
|
UPROPERTY(EditAnywhere, Category = "Movement Properties")
|
||||||
float SprintSpeed = 1500.0f;
|
float SprintSpeed = 1500.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Aiming")
|
||||||
|
float bIsAimingMode = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user