From be4ea78ab402745608fb37ef332834649f83f93d Mon Sep 17 00:00:00 2001 From: MH261677 Date: Mon, 9 Oct 2023 13:51:21 +0100 Subject: [PATCH] Modified recoil limits --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 +-- .../EndlessVendettaCharacter.cpp | 14 ++++++++++- .../EndlessVendettaCharacter.h | 3 +++ .../WeaponSystem/BaseWeaponClass.cpp | 25 +++++++++++++++---- .../WeaponSystem/BaseWeaponClass.h | 10 ++++++++ 5 files changed, 48 insertions(+), 8 deletions(-) diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 1cd92c0a..e7dcb857 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5431985cf2ef161d75bd2da6d55c3513b80f5c5f13010f132c47f57f2e5b84dc -size 42521 +oid sha256:65d9f1286e3e2a0afeb00fd61e2a4ad5d105f8c4ea61cf146761901c810ea4bb +size 42451 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 26f9566f..d27bdc42 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -92,6 +92,7 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* //Weapon Shooting EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::FireCaller); + EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopFire); EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::GunRightClick); EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopGunRightClick); @@ -229,7 +230,6 @@ void AEndlessVendettaCharacter::EquipSecondary() //Calls the fire function in the baseWeaponClass void AEndlessVendettaCharacter::FireCaller() { - UE_LOG(LogTemp, Warning, TEXT("Tap Fire")); if (IsValid(PrimaryWeapon)) { PrimaryWeapon->Fire(); @@ -240,6 +240,18 @@ void AEndlessVendettaCharacter::FireCaller() } } +void AEndlessVendettaCharacter::StopFire() +{ + if (IsValid(PrimaryWeapon)) + { + PrimaryWeapon->CancelFire(); + } + if (IsValid(SecondaryWeapon)) + { + SecondaryWeapon->CancelFire(); + } +} + void AEndlessVendettaCharacter::GunRightClick() { if (IsValid(PrimaryWeapon) && !bIsScoped) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 4f8b754d..3fb99716 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -123,6 +123,9 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void GunReload(); + UFUNCTION(BlueprintCallable, Category = "Weapons") + void StopFire(); + UArrowComponent* ScopedLocationArrow; UPROPERTY(EditAnywhere, Category = "Dont Touch") diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index dd57b613..c80e5bbd 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -85,12 +85,26 @@ void ABaseWeaponClass::ApplyRecoil(float DeltaTime) { float amplitude = RecoilCurve->GetFloatValue(recoilTime); //get current value of curve in time recoilTime += DeltaTime; - playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime)); + if (bulletCountShoot <= 3) playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime)); + traceEnd = traceStart + (UKismetMathLibrary::GetForwardVector(playerInWorld->GetControlRotation() * GetRecoilPitch(amplitude, recoilTime))); + //UE_LOG(LogTemp, Warning, TEXT("Controller pitch: Pitch: %f Yaw: %f, Roll: %f"), playerInWorld->GetControlRotation().Pitch, playerInWorld->GetControlRotation().Yaw, playerInWorld->GetControlRotation().Roll); playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime)); + UE_LOG(LogTemp, Warning, TEXT("recoilTime: %f"), recoilTime); UpdateSamples(amplitude, recoilTime); } } + +//void ABaseWeaponClass::RecoilVerticalLimit(FHitResult Outhit) +//{ +// double currentCameraRot = playerInWorld->GetControlRotation().Pitch; +// if (bulletCountShoot >= 3) +// { +// +// } +//} + + void ABaseWeaponClass::nullSamples() { recoilCurvet = 0; @@ -133,6 +147,8 @@ void ABaseWeaponClass::ClickDetectionTimer() void ABaseWeaponClass::CancelFire() { GetWorldTimerManager().ClearTimer(timerHandle); + UE_LOG(LogTemp, Display, TEXT("FireCancelled")); + bulletCountShoot = 0; } void ABaseWeaponClass::Fire() @@ -140,14 +156,12 @@ void ABaseWeaponClass::Fire() if(currentAmmoCount > 0) { //do damage fallof based off distance - FHitResult outHit; - FVector traceStart; - FVector traceEnd; traceStart = GunStartArrow->GetComponentLocation(); traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance); FCollisionQueryParams collisionParams; collisionParams.AddIgnoredActor(playerInWorld); collisionParams.AddIgnoredActor(this); + /*RecoilVerticalLimit(outHit);*/ if (GetWorldTimerManager().IsTimerActive(timerHandle)) { return; @@ -160,9 +174,10 @@ void ABaseWeaponClass::Fire() UE_LOG(LogTemp, Display, TEXT("Ammo Count: %d"), currentAmmoCount); GenerateRecoilVector(); ClickDetectionTimer(); + bulletCountShoot += 1; if (outHit.bBlockingHit) { - UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName()); + //UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName()); } } else if(currentAmmoCount <= 0) diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index 1d07fb65..0edef8f6 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -113,6 +113,16 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void WeaponReload(); + FHitResult outHit; + FVector traceStart; + FVector traceEnd; + + //UFUNCTION(BlueprintCallable, Category = "Weapons") + //void RecoilVerticalLimit(FHitResult Outhit); + + UPROPERTY(EditAnywhere) + int bulletCountShoot; //Gets how many bullets shot per + private: UArrowComponent* GunStartArrow;