diff --git a/Content/Blueprints/Items/ShotGun.uasset b/Content/Blueprints/Items/ShotGun.uasset index e732e7d..4dffcc1 100644 Binary files a/Content/Blueprints/Items/ShotGun.uasset and b/Content/Blueprints/Items/ShotGun.uasset differ diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp index 1cc0d29..6639f7e 100644 --- a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -20,8 +20,11 @@ void UShootingComponent::BeginPlay() Super::BeginPlay(); PlayerCharacter = Cast(GetOwner()); -} + CameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager; + DefaultFOV = CameraManager->GetFOVAngle(); + TargetFOV = DefaultFOV; +} void UShootingComponent::Shoot() { @@ -88,6 +91,7 @@ void UShootingComponent::Reload() if (!IsValid(CurrentGun) || bIsReloading) return; bIsReloading = true; + StopAiming(); CurrentGun->CurrentAmmo = CurrentGun->MaxAmmo; PlayerCharacter->GetWorldTimerManager().SetTimer(ReloadTimer, this, &UShootingComponent::ReloadCompleted, CurrentGun->ReloadTime, false); @@ -120,6 +124,8 @@ void UShootingComponent::PickUpGun(AGunBase* gunItem) void UShootingComponent::DropGun() { if (!IsValid(CurrentGun)) return; + + StopAiming(); FVector ForwardVector = PlayerCharacter->GetActorForwardVector(); FVector PlayerPos = PlayerCharacter->GetActorLocation(); @@ -168,6 +174,7 @@ void UShootingComponent::SwitchGun() SecondaryGun = temp; bIsFirstGunSelected = !bIsFirstGunSelected; + StopAiming(); // Debug info 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 void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - // ... + float CurrentFOV = CameraManager->GetFOVAngle(); + float NewFOV = FMath::FInterpTo(CurrentFOV, TargetFOV, DeltaTime, AimingSpeed); + CameraManager->SetFOV(NewFOV); } - diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index d2cffe6..83811d9 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -57,7 +57,8 @@ void AExoPlayerController::SetupInputComponent() EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerStartSprint); EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &AExoPlayerController::PlayerStopSprint); 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(ChangeWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerChangeWeapon); EnhancedInputComponent->BindAction(SelectFirstWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSelectFirstWeapon); @@ -159,9 +160,14 @@ void AExoPlayerController::PlayerShoot() ShootingComponent->Shoot(); } -void AExoPlayerController::PlayerAim() +void AExoPlayerController::PlayerStartAim() { - + ShootingComponent->StartAiming(); +} + +void AExoPlayerController::PlayerStopAim() +{ + ShootingComponent->StopAiming(); } void AExoPlayerController::PlayerMeleAttack() diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h index f70a72e..04ded36 100644 --- a/Source/Exo/Public/Characters/Components/ShootingComponent.h +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -25,6 +25,9 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character") TObjectPtr PlayerCharacter; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera") + TObjectPtr CameraManager; + protected: // Called when the game starts virtual void BeginPlay() override; @@ -54,6 +57,15 @@ public: UFUNCTION(Category = "Shooting") 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") float DropGunRange = 20.0f; @@ -74,6 +86,9 @@ private: bool bCanShoot = true; bool bIsReloading = false; + float DefaultFOV; + float TargetFOV; + bool bIsFirstGunSelected = true; float MeleDamageValue = 50.f; diff --git a/Source/Exo/Public/Items/GunBase.h b/Source/Exo/Public/Items/GunBase.h index f5ed743..f75af53 100644 --- a/Source/Exo/Public/Items/GunBase.h +++ b/Source/Exo/Public/Items/GunBase.h @@ -31,6 +31,9 @@ public: UPROPERTY(EditAnywhere, Category = "Shooting") float ReloadTime = 3.0f; + UPROPERTY(EditAnywhere, Category = "Shooting") + float AimingFOV = 55.0f; + UPROPERTY(EditAnywhere, Category = "Ammo") int32 CurrentAmmo = 10; diff --git a/Source/Exo/Public/Player/ExoPlayerController.h b/Source/Exo/Public/Player/ExoPlayerController.h index 38f1d9e..61064e6 100644 --- a/Source/Exo/Public/Player/ExoPlayerController.h +++ b/Source/Exo/Public/Player/ExoPlayerController.h @@ -63,7 +63,10 @@ protected: void PlayerShoot(); // LPM UFUNCTION(BlueprintCallable, Category = "Input") - void PlayerAim(); // PPM - nieprzypisane + void PlayerStartAim(); // PPM (pressed) + + UFUNCTION(BlueprintCallable, Category = "Input") + void PlayerStopAim(); // PPM (released) UFUNCTION(BlueprintCallable, Category = "Input") void PlayerMeleAttack(); // V - nieprzypisane @@ -82,9 +85,8 @@ protected: UFUNCTION(BlueprintCallable, Category = "Input") void PlayerReload(); // R - - -protected: + + UPROPERTY(EditAnywhere, Category = "Input") TObjectPtr InputContext;