feat: add aiming
Added aiming feature, possible when holding gun. Aiming FOV depends on gun
This commit is contained in:
parent
fa9cf7ef3b
commit
0b52fe2b4f
Binary file not shown.
|
|
@ -20,8 +20,11 @@ void UShootingComponent::BeginPlay()
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
PlayerCharacter = Cast<AExoPlayerCharacter>(GetOwner());
|
PlayerCharacter = Cast<AExoPlayerCharacter>(GetOwner());
|
||||||
}
|
CameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
|
||||||
|
|
||||||
|
DefaultFOV = CameraManager->GetFOVAngle();
|
||||||
|
TargetFOV = DefaultFOV;
|
||||||
|
}
|
||||||
|
|
||||||
void UShootingComponent::Shoot()
|
void UShootingComponent::Shoot()
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +91,7 @@ void UShootingComponent::Reload()
|
||||||
if (!IsValid(CurrentGun) || bIsReloading) return;
|
if (!IsValid(CurrentGun) || bIsReloading) return;
|
||||||
|
|
||||||
bIsReloading = true;
|
bIsReloading = true;
|
||||||
|
StopAiming();
|
||||||
|
|
||||||
CurrentGun->CurrentAmmo = CurrentGun->MaxAmmo;
|
CurrentGun->CurrentAmmo = CurrentGun->MaxAmmo;
|
||||||
PlayerCharacter->GetWorldTimerManager().SetTimer(ReloadTimer, this, &UShootingComponent::ReloadCompleted, CurrentGun->ReloadTime, false);
|
PlayerCharacter->GetWorldTimerManager().SetTimer(ReloadTimer, this, &UShootingComponent::ReloadCompleted, CurrentGun->ReloadTime, false);
|
||||||
|
|
@ -121,6 +125,8 @@ void UShootingComponent::DropGun()
|
||||||
{
|
{
|
||||||
if (!IsValid(CurrentGun)) return;
|
if (!IsValid(CurrentGun)) return;
|
||||||
|
|
||||||
|
StopAiming();
|
||||||
|
|
||||||
FVector ForwardVector = PlayerCharacter->GetActorForwardVector();
|
FVector ForwardVector = PlayerCharacter->GetActorForwardVector();
|
||||||
FVector PlayerPos = PlayerCharacter->GetActorLocation();
|
FVector PlayerPos = PlayerCharacter->GetActorLocation();
|
||||||
FVector DroppedGunPos = PlayerPos + (ForwardVector * DropGunRange);
|
FVector DroppedGunPos = PlayerPos + (ForwardVector * DropGunRange);
|
||||||
|
|
@ -168,6 +174,7 @@ void UShootingComponent::SwitchGun()
|
||||||
SecondaryGun = temp;
|
SecondaryGun = temp;
|
||||||
|
|
||||||
bIsFirstGunSelected = !bIsFirstGunSelected;
|
bIsFirstGunSelected = !bIsFirstGunSelected;
|
||||||
|
StopAiming();
|
||||||
|
|
||||||
// Debug info
|
// Debug info
|
||||||
if (bIsFirstGunSelected)
|
if (bIsFirstGunSelected)
|
||||||
|
|
@ -180,11 +187,25 @@ void UShootingComponent::SwitchGun()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UShootingComponent::StartAiming()
|
||||||
|
{
|
||||||
|
if (IsValid(CurrentGun))
|
||||||
|
{
|
||||||
|
TargetFOV = CurrentGun->AimingFOV;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UShootingComponent::StopAiming()
|
||||||
|
{
|
||||||
|
TargetFOV = DefaultFOV;
|
||||||
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||||
{
|
{
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
// ...
|
float CurrentFOV = CameraManager->GetFOVAngle();
|
||||||
|
float NewFOV = FMath::FInterpTo(CurrentFOV, TargetFOV, DeltaTime, AimingSpeed);
|
||||||
|
CameraManager->SetFOV(NewFOV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ void AExoPlayerController::SetupInputComponent()
|
||||||
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartSprint);
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartSprint);
|
||||||
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopSprint);
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopSprint);
|
||||||
EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerShoot);
|
EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerShoot);
|
||||||
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerAim);
|
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartAim);
|
||||||
|
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopAim);
|
||||||
EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack);
|
EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack);
|
||||||
EnhancedInputComponent->BindAction(ChangeWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerChangeWeapon);
|
EnhancedInputComponent->BindAction(ChangeWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerChangeWeapon);
|
||||||
EnhancedInputComponent->BindAction(SelectFirstWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSelectFirstWeapon);
|
EnhancedInputComponent->BindAction(SelectFirstWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSelectFirstWeapon);
|
||||||
|
|
@ -159,9 +160,14 @@ void AExoPlayerController::PlayerShoot()
|
||||||
ShootingComponent->Shoot();
|
ShootingComponent->Shoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerAim()
|
void AExoPlayerController::PlayerStartAim()
|
||||||
{
|
{
|
||||||
|
ShootingComponent->StartAiming();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AExoPlayerController::PlayerStopAim()
|
||||||
|
{
|
||||||
|
ShootingComponent->StopAiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerMeleAttack()
|
void AExoPlayerController::PlayerMeleAttack()
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
|
||||||
TObjectPtr<AExoPlayerCharacter> PlayerCharacter;
|
TObjectPtr<AExoPlayerCharacter> PlayerCharacter;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
|
TObjectPtr<APlayerCameraManager> CameraManager;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts
|
// Called when the game starts
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
@ -54,6 +57,15 @@ public:
|
||||||
UFUNCTION(Category = "Shooting")
|
UFUNCTION(Category = "Shooting")
|
||||||
void SelectGun(bool bSelectFirstSlot);
|
void SelectGun(bool bSelectFirstSlot);
|
||||||
|
|
||||||
|
UFUNCTION(Category = "Shooting")
|
||||||
|
void StartAiming();
|
||||||
|
|
||||||
|
UFUNCTION(Category = "Shooting")
|
||||||
|
void StopAiming();
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting")
|
||||||
|
float AimingSpeed = 30.0f;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Shooting")
|
||||||
float DropGunRange = 20.0f;
|
float DropGunRange = 20.0f;
|
||||||
|
|
||||||
|
|
@ -74,6 +86,9 @@ private:
|
||||||
bool bCanShoot = true;
|
bool bCanShoot = true;
|
||||||
bool bIsReloading = false;
|
bool bIsReloading = false;
|
||||||
|
|
||||||
|
float DefaultFOV;
|
||||||
|
float TargetFOV;
|
||||||
|
|
||||||
bool bIsFirstGunSelected = true;
|
bool bIsFirstGunSelected = true;
|
||||||
|
|
||||||
float MeleDamageValue = 50.f;
|
float MeleDamageValue = 50.f;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@ public:
|
||||||
UPROPERTY(EditAnywhere, Category = "Shooting")
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
float ReloadTime = 3.0f;
|
float ReloadTime = 3.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float AimingFOV = 55.0f;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Ammo")
|
UPROPERTY(EditAnywhere, Category = "Ammo")
|
||||||
int32 CurrentAmmo = 10;
|
int32 CurrentAmmo = 10;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,10 @@ protected:
|
||||||
void PlayerShoot(); // LPM
|
void PlayerShoot(); // LPM
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void PlayerAim(); // PPM - nieprzypisane
|
void PlayerStartAim(); // PPM (pressed)
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
|
void PlayerStopAim(); // PPM (released)
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void PlayerMeleAttack(); // V - nieprzypisane
|
void PlayerMeleAttack(); // V - nieprzypisane
|
||||||
|
|
@ -84,7 +87,6 @@ protected:
|
||||||
void PlayerReload(); // R
|
void PlayerReload(); // R
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Input")
|
UPROPERTY(EditAnywhere, Category = "Input")
|
||||||
TObjectPtr<UInputMappingContext> InputContext;
|
TObjectPtr<UInputMappingContext> InputContext;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user