From d12573f6cc14bbbc55b0368bd3adc017ab1ed708 Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Mon, 23 Oct 2023 14:01:09 +0100 Subject: [PATCH 1/4] Added Sniper Weapon and started creating Base Functionality --- .../BaseWeapons/Snipers/BaseSniper.uasset | 3 ++ .../EndlessVendettaCharacter.cpp | 13 ++++++- .../EndlessVendettaCharacter.h | 4 ++ .../WeaponSystem/BaseWeaponClass.h | 4 +- .../WeaponSystem/SniperClass.cpp | 38 +++++++++++++++++++ .../WeaponSystem/SniperClass.h | 36 ++++++++++++++++++ 6 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset create mode 100644 EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset new file mode 100644 index 00000000..410bc4c2 --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d4a7e220c05cd641cf8f6465c767efb4bf895ca9ac7d473530dff9daeecac55 +size 124137 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 3cfc910d..cd739e62 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -10,6 +10,7 @@ #include "AI/EnemyCharacter.h" #include "GameFramework/CharacterMovementComponent.h" #include "Kismet/GameplayStatics.h" +#include "GameFramework/MovementComponent.h" ////////////////////////////////////////////////////////////////////////// @@ -71,7 +72,17 @@ void AEndlessVendettaCharacter::Tick(float DeltaTime) Super::Tick(DeltaTime); WeaponPickUpSystem(); - + + MoveGroundSpeed = Cast(GetComponentByClass(UMovementComponent::StaticClass()))->Velocity.Size(); + + if (MoveGroundSpeed > 0) + { + bIsPlayerMoving = true; + } + else if (MoveGroundSpeed <= 0) + { + bIsPlayerMoving = false; + } } void AEndlessVendettaCharacter::WeaponPickUpSystem() diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index a3d099ce..775f12f2 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -93,6 +93,10 @@ public: int Money = 2000; bool bIsReloading = false; + bool bIsPlayerMoving = false; + + double MoveGroundSpeed; + /** Look Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputAction* LookAction; diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index 36de56ca..1de19d01 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -25,7 +25,7 @@ protected: // Called when the game starts or when spawned virtual void BeginPlay() override; - void ApplyRecoil(float DeltaTime); + virtual void ApplyRecoil(float DeltaTime); void GenerateRecoilVector(); @@ -159,7 +159,7 @@ public: //UFUNCTION(BlueprintCallable, Category = "Weapons") //void RecoilVerticalLimit(FHitResult Outhit); - UPROPERTY(EditAnywhere) + UPROPERTY(VisibleAnywhere) int bulletCountShoot; //Gets how many bullets shot per void Interact() override; diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp new file mode 100644 index 00000000..b357df11 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp @@ -0,0 +1,38 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "SniperClass.h" +#include "EndlessVendettaCharacter.h" + +// Sets default values +ASniperClass::ASniperClass() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; +} + +// Called when the game starts or when spawned +void ASniperClass::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void ASniperClass::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); +} + +void ASniperClass::Fire() +{ + +} + +void ASniperClass::ApplyRecoil(float DeltaTime) +{ + if (endlessVendettaChar->bIsPlayerMoving) + { + UE_LOG(LogTemp, Display, TEXT("playerMovingIsTrue")); + } +} diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h new file mode 100644 index 00000000..1b590477 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h @@ -0,0 +1,36 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BaseWeaponClass.h" +#include "EndlessVendettaCharacter.h" +#include "SniperClass.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API ASniperClass : public ABaseWeaponClass +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + ASniperClass(); + +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + +protected: + + virtual void Fire() override; + + virtual void ApplyRecoil(float DeltaTime) override; + +}; From 848430aebd59571c7efcc0e4c143086c01eb32c8 Mon Sep 17 00:00:00 2001 From: MH261677 Date: Thu, 26 Oct 2023 15:49:11 +0100 Subject: [PATCH 2/4] Finished Creating Sniper Weapon --- .../BaseWeapons/Snipers/BaseSniper.uasset | 4 +- .../BaseWeapons/WBP_AmmoCount.uasset | 4 +- .../7/VS/TBSU6BHEHN191N9FG8A6XN.uasset | 3 + .../WeaponSystem/BaseWeaponClass.h | 11 +-- .../WeaponSystem/SniperClass.cpp | 68 +++++++++++++++++-- .../WeaponSystem/SniperClass.h | 8 ++- 6 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/VS/TBSU6BHEHN191N9FG8A6XN.uasset diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset index 410bc4c2..dec79762 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4d4a7e220c05cd641cf8f6465c767efb4bf895ca9ac7d473530dff9daeecac55 -size 124137 +oid sha256:d5625ec21d5212c05429ac81906d5aa5e6ee935ee0bcbcdd16477cbd64165c16 +size 125077 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset index ff0850c9..8506b4d5 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4aef926e64cc0bd15cd6df6c9683311954a37d3a4576cd79a564efe16ef7920d -size 64353 +oid sha256:12a2bf04dd00e6b7507070952dc3382734b02f049bd6a73a24f066b802071ca6 +size 64438 diff --git a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/VS/TBSU6BHEHN191N9FG8A6XN.uasset b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/VS/TBSU6BHEHN191N9FG8A6XN.uasset new file mode 100644 index 00000000..34849915 --- /dev/null +++ b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/VS/TBSU6BHEHN191N9FG8A6XN.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b166a03dba174d55220b56cde59bb17914ac485c6b2b4055d1c99ad6d6d3da7 +size 6183 diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index 1de19d01..531048b8 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -7,6 +7,7 @@ #include "Components/ArrowComponent.h" #include "Kismet/KismetMathLibrary.h" #include "EndlessVendetta/InteractionInterface.h" +#include "Engine/EngineTypes.h" #include "BaseWeaponClass.generated.h" class AEndlessVendettaCharacter; @@ -54,7 +55,11 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; void ReloadTimer(); - + + float currentPitch; + + UPROPERTY(EditAnywhere) + float BulletDistance; UPROPERTY(EditAnywhere, BlueprintReadWrite) FString WeaponName; @@ -177,14 +182,10 @@ protected: private: - UPROPERTY(EditAnywhere) - float BulletDistance; - float originalMagnitude; float originalMaxAngleLeft; float originalMaxAngleRight; float originalMinMultiplier; - float currentPitch; }; diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp index b357df11..9ace82f6 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.cpp @@ -2,7 +2,10 @@ #include "SniperClass.h" -#include "EndlessVendettaCharacter.h" +#include "EndlessVendetta/EndlessVendettaCharacter.h" +#include "EndlessVendetta/AI/AICharacter.h" +#include "Engine/DamageEvents.h" +#include "Kismet/GameplayStatics.h" // Sets default values ASniperClass::ASniperClass() @@ -15,24 +18,77 @@ ASniperClass::ASniperClass() void ASniperClass::BeginPlay() { Super::BeginPlay(); - } // Called every frame void ASniperClass::Tick(float DeltaTime) { - Super::Tick(DeltaTime); + ApplyRecoil(DeltaTime); + recoilMagnitude = 1; + if(endlessVendettaChar->bIsPlayerMoving == false ) + { + recoilResultPitch = 0; + recoilMagnitude = -1; + } + if (currentPitch < 0 && bStopShooting) + { + float increment = currentPitch * DeltaTime * 8; + currentPitch -= increment; + playerInWorld->AddControllerPitchInput(-increment); + } } void ASniperClass::Fire() { - + if(currentAmmoCount > 0 && !bSingleShotOnly) + { + bSingleShotOnly = true; + //do damage fallof based off distance + traceStart = GunStartArrow->GetComponentLocation(); + traceEnd = traceStart + (GunStartArrow->GetForwardVector() * BulletDistance); + if (GetWorldTimerManager().IsTimerActive(timerHandle)) return; + GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams); + DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Black , false, 0.2f, 0U, 0.2f); + playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1); + currentAmmoCount -= 1; + bulletCountShoot += 1; + bStopShooting = false; + GenerateRecoilVector(); + ApplyRecoil(UGameplayStatics::GetWorldDeltaSeconds(this->GetWorld())); + this->GetWorld()->GetTimerManager().SetTimer(SniperTimerHandle, this, &ASniperClass::StopFire, FireRate, false); + if (outHit.bBlockingHit) + { + UE_LOG(LogTemp, Display, TEXT("Hit: %s"), *outHit.GetActor()->GetName()); + if (!Cast(outHit.GetActor())) return; + Cast(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this); + } + } + else if(currentAmmoCount <= 0) + { + UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount); + } } void ASniperClass::ApplyRecoil(float DeltaTime) { - if (endlessVendettaChar->bIsPlayerMoving) + if (recoilTime < 0.3) { - UE_LOG(LogTemp, Display, TEXT("playerMovingIsTrue")); + float amplitude = RecoilCurve->GetFloatValue(recoilTime); //get current value of curve in time + recoilTime += DeltaTime; + + playerInWorld->AddControllerPitchInput(GetRecoilPitch(amplitude, recoilTime)); + + currentPitch += GetRecoilPitch(amplitude,recoilTime); + + playerInWorld->AddControllerPitchInput(FMath::RandRange(-5 * DeltaTime, 5* DeltaTime)); + GunStartArrow->AddRelativeRotation(FRotator(-GetRecoilPitch(amplitude, recoilTime), 0, 0)); + playerInWorld->AddControllerYawInput(GetRecoilYaw(amplitude, recoilTime)); + + UpdateSamples(amplitude, recoilTime); } } + +void ASniperClass::StopFire() +{ + bSingleShotOnly = false; +} diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h index 1b590477..721020b1 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/SniperClass.h @@ -4,7 +4,6 @@ #include "CoreMinimal.h" #include "BaseWeaponClass.h" -#include "EndlessVendettaCharacter.h" #include "SniperClass.generated.h" /** @@ -27,10 +26,17 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; +private: + + bool bSingleShotOnly; + FTimerHandle SniperTimerHandle; + protected: virtual void Fire() override; virtual void ApplyRecoil(float DeltaTime) override; + + void StopFire(); }; From 6c8e5276f9e39019174683b5d8df3854866da9de Mon Sep 17 00:00:00 2001 From: MH261677 Date: Thu, 26 Oct 2023 15:50:25 +0100 Subject: [PATCH 3/4] Updating Magazine Size Back To Default --- .../Blueprints/BaseWeapons/Snipers/BaseSniper.uasset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset index dec79762..34390329 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Snipers/BaseSniper.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d5625ec21d5212c05429ac81906d5aa5e6ee935ee0bcbcdd16477cbd64165c16 +oid sha256:c4edd4b9c090f7fd40cb88de61fd3f0a2cf27d5b2e959e8a1189e705df6a9707 size 125077 From 8678376ba6199663b8c5d7420a67823dbc9626de Mon Sep 17 00:00:00 2001 From: MH261677 Date: Thu, 26 Oct 2023 16:00:46 +0100 Subject: [PATCH 4/4] Added Shotgun Base Weapon --- .../Shotguns/BP_BaseShotgun.uasset | 3 +++ .../5/1H/2QRFI3J5JT02V2G1QP4P99.uasset | 3 +++ .../6/TX/BTC9S0W28D5I25IOL56715.uasset | 4 ++-- .../WeaponSystem/ShotgunClass.cpp | 10 +++++++++ .../WeaponSystem/ShotgunClass.h | 21 +++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Shotguns/BP_BaseShotgun.uasset create mode 100644 EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/5/1H/2QRFI3J5JT02V2G1QP4P99.uasset create mode 100644 EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.h diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Shotguns/BP_BaseShotgun.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Shotguns/BP_BaseShotgun.uasset new file mode 100644 index 00000000..ca208dae --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Shotguns/BP_BaseShotgun.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:329bb4534943e949f235c44d9782f62012b4e728fa4a566615a718a2ae0f1bde +size 124581 diff --git a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/5/1H/2QRFI3J5JT02V2G1QP4P99.uasset b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/5/1H/2QRFI3J5JT02V2G1QP4P99.uasset new file mode 100644 index 00000000..39871f58 --- /dev/null +++ b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/5/1H/2QRFI3J5JT02V2G1QP4P99.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56271e75ce388bac1e70abc1085fcf019d41a311ac70ff84ed3f7bbec53aa6ec +size 6426 diff --git a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/6/TX/BTC9S0W28D5I25IOL56715.uasset b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/6/TX/BTC9S0W28D5I25IOL56715.uasset index fa64ab8e..01662c33 100644 --- a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/6/TX/BTC9S0W28D5I25IOL56715.uasset +++ b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/6/TX/BTC9S0W28D5I25IOL56715.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:39162e6e995a0f6846b1a806d1fa532ddc0af51fc910ab83b5c988fc591f91ff -size 4768 +oid sha256:132a3e687f7729d821313a19996f7ec6d6e423a6fc5adb3035cc427c8333d7f3 +size 4742 diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.cpp new file mode 100644 index 00000000..266ae616 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.cpp @@ -0,0 +1,10 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ShotgunClass.h" + +AShotgunClass::AShotgunClass() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; +} diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.h new file mode 100644 index 00000000..8bf23c16 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/ShotgunClass.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BaseWeaponClass.h" +#include "ShotgunClass.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API AShotgunClass : public ABaseWeaponClass +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AShotgunClass(); + +};