From 5743e885e0135bd06cf73bc38bb58707019a650c Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Mon, 2 Oct 2023 13:36:19 +0100 Subject: [PATCH] Basic Shooting functionality fixed Shooting now shoots a ray out and detects what object is being hit --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 +- .../AssaultRifles/BP_BaseAssaultRifle.uasset | 4 +- .../BaseWeapons/BP_BaseWeapon.uasset | 4 +- .../Architecture/Floor_400x400.uasset | 4 +- .../StarterContent/Audio/Collapse01.uasset | 4 +- .../0/3Z/SNIBJQL2L6YHSC7MTTK1C2.uasset | 2 +- .../BountySystem/BountyClass.h | 2 +- .../EndlessVendettaCharacter.cpp | 131 +++--------------- .../EndlessVendettaCharacter.h | 5 +- .../WeaponSystem/BaseWeaponClass.cpp | 33 ++--- .../WeaponSystem/BaseWeaponClass.h | 8 +- 11 files changed, 57 insertions(+), 144 deletions(-) diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 68a7823a..fda783bd 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:072d87c768407249e6e50f7b87ab9a88392c17cf82c72934e3c947e2943210bb -size 26284 +oid sha256:d580d82ff6abdbebffa1e57dc264fb6e4b0e6c53e28aa0c853b56149f7867471 +size 27305 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/AssaultRifles/BP_BaseAssaultRifle.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/AssaultRifles/BP_BaseAssaultRifle.uasset index 50209cd2..52b41107 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/AssaultRifles/BP_BaseAssaultRifle.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/AssaultRifles/BP_BaseAssaultRifle.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8b311799aa263b7af6d3eb738da33d39b0d40d7883bf0a4e3cb6024e06157cec -size 37724 +oid sha256:21afd371e599a3fb2c37e3662406978c3305c602a1c77bb3717e9bc4f2514b48 +size 35926 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/BP_BaseWeapon.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/BP_BaseWeapon.uasset index 0aef22ed..063848e3 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/BP_BaseWeapon.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/BP_BaseWeapon.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a4dfbc572d0f67be5a3c6898946ce7fce2895174236407ce9910f99c59690367 -size 28778 +oid sha256:51cc0f9f0adae065e9941acdd88abe2fe5f7015a3a5343a63f7b0507e90c21ed +size 28900 diff --git a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset index c2a34afc..ec9ee977 100644 --- a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset +++ b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4c0ecf0ac0702cc2bd355ec050232a61c49e10f102448efbeb735a51824adef6 -size 14948 +oid sha256:d4e6c0e1dad79feeaa5078889de9cf4c6753f1e77cf7d17a3eb3de082b91d4ae +size 14831 diff --git a/EndlessVendetta/Content/StarterContent/Audio/Collapse01.uasset b/EndlessVendetta/Content/StarterContent/Audio/Collapse01.uasset index 198f128d..5e3ff30e 100644 --- a/EndlessVendetta/Content/StarterContent/Audio/Collapse01.uasset +++ b/EndlessVendetta/Content/StarterContent/Audio/Collapse01.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:43d44b5a53fbbfc62522f67ad9523360b15677e3d0caeea96f4d9d0580a013cd -size 353935 +oid sha256:85c827023ee4b466228ec65e92b4b4a0415a106de041ac1c2cab481a2a5dfa8d +size 348532 diff --git a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/0/3Z/SNIBJQL2L6YHSC7MTTK1C2.uasset b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/0/3Z/SNIBJQL2L6YHSC7MTTK1C2.uasset index 4f6bab25..4777b0ad 100644 --- a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/0/3Z/SNIBJQL2L6YHSC7MTTK1C2.uasset +++ b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/0/3Z/SNIBJQL2L6YHSC7MTTK1C2.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fdab805d14a7bc4f2fa61abc0106161cf2626e8857ae14089d5e4c93f9a320d6 +oid sha256:5b8b34286278ebb69adb37de9d922ea859ecab2e2547f7e3a634d75c61522828 size 5061 diff --git a/EndlessVendetta/Source/EndlessVendetta/BountySystem/BountyClass.h b/EndlessVendetta/Source/EndlessVendetta/BountySystem/BountyClass.h index 9dfb87e1..4f65bae9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/BountySystem/BountyClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/BountySystem/BountyClass.h @@ -7,7 +7,7 @@ #include "GameFramework/Actor.h" #include "BountyClass.generated.h" -DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedFirstCheckpoint) +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedFirstCheckpoint); UCLASS() class ENDLESSVENDETTA_API ABountyClass : public AActor diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 448d805c..ace56207 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -59,7 +59,7 @@ void AEndlessVendettaCharacter::BeginPlay() GadgetManager->SpawnGadgets(Cast(PlayersCamera)); break; } - + } //////////////////////////////////////////////////////////////////////////// Input @@ -82,13 +82,14 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* // Gadget Toggling EnhancedInputComponent->BindAction(ReconAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleRecon); EnhancedInputComponent->BindAction(CombatAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleCombat); - + //Weapon Switching EnhancedInputComponent->BindAction(EquipPrimaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipPrimary); EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipSecondary); //Weapon Shooting EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller); + EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller); } } @@ -145,12 +146,10 @@ void AEndlessVendettaCharacter::EquipPrimary() } if (IsValid(SecondaryWeapon)) EquipSecondary(); - - // Marcel I respect you, like you and what not, please for the love of god don't touch these two guard clauses - ///////////////////////////////////////////////////////////////////////////////////////////////////////////// - if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;///////////////////////// - if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;/////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return; + if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return; + FActorSpawnParameters spawnParams; spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; @@ -163,131 +162,47 @@ void AEndlessVendettaCharacter::EquipPrimary() //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor PrimaryWeapon = Cast(PrimaryWeaponActor); - - //If primary weapon is not there but secondary weapon is it will call equipSecondary. - //EquipSecondary checks and sees that secondary is there so it will call to destroy itself - //Code goes back and sees primary weapon is not there anymore and spawns it in. - //Same thing for the EquipSecondary() - - // if (!IsValid(PrimaryWeapon)) - // { - // if (IsValid(SecondaryWeapon)) EquipSecondary(); - // - // UE_LOG(LogTemp, Display, TEXT("Primary equipped")); - // bHasRifle = true; - // FActorSpawnParameters spawnParams; - // spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - // FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - // //Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass - // AActor* PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); - // PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); - // //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object - // //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor - // PrimaryWeapon = Cast(PrimaryWeaponActor); - // - // } - // else if (IsValid(PrimaryWeapon)) - // { - // PrimaryWeapon->Destroy(); - // bHasRifle = false; - // } } void AEndlessVendettaCharacter::EquipSecondary() { if (IsValid(SecondaryWeapon)) - { - SecondaryWeapon->Destroy(); + { + SecondaryWeapon->Destroy(); SecondaryWeapon = nullptr; - bHasRifle = false; - return; - } + bHasRifle = false; + return; + } if (IsValid(PrimaryWeapon)) EquipPrimary(); - - // Marcel I respect you, like you and what not, please for the love of god don't touch these two guard clauses - ///////////////////////////////////////////////////////////////////////////////////////////////////////////// - if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;///////////////////////// - if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;/////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return; + if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return; + FActorSpawnParameters spawnParams; spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - + bHasRifle = true; AActor* SecondaryWeaponActor = GetWorld()->SpawnActor(SecondaryWeaponClass, spawnParams); SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); SecondaryWeapon = Cast(SecondaryWeaponActor); - - // if (!IsValid(SecondaryWeapon)) - // { - // if (IsValid(PrimaryWeapon)) EquipPrimary(); - // - // UE_LOG(LogTemp, Display, TEXT("Secondary equipped")); - // bHasRifle = true; - // FActorSpawnParameters spawnParams; - // spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - // FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - // AActor* SecondaryWeaponActor = GetWorld()->SpawnActor(SecondaryWeaponClass, spawnParams); - // SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); - // SecondaryWeapon = Cast(SecondaryWeaponActor); - // } - // else if (IsValid(SecondaryWeapon)) - // { - // SecondaryWeapon->Destroy(); - // bHasRifle = false; - // } - + + } //Calls the fire function in the baseWeaponClass void AEndlessVendettaCharacter::TapFireCaller() { UE_LOG(LogTemp, Warning, TEXT("Tap Fire")); - // if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon)) - // { - // PrimaryWeaponClass.GetDefaultObject()->TapFire(); - // } + if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon)) + { + PrimaryWeapon->TapFire(); + } } -//POTENTIAL PICKUP SYSTEM NEEDS CHANGING BUT YES - -//Called from Player BluePrints -/*void AEndlessVendettaCharacter::WeaponPickUpSystem(AActor* PickedUpWeapon) -{ - ABaseWeaponClass* WeaponInWorld = Cast(PickedUpWeapon); - if(WeaponInWorld->IsA(ABaseWeaponClass::StaticClass())) - { - if(PrimaryWeapon) - { - UE_LOG(LogTemp, Display, TEXT("Primary Weapon Picked up")); - bHasRifle = true; - FVector loc = GetActorLocation() + FVector(-50, 0, 0); - FRotator rot = GetActorRotation(); - FActorSpawnParameters spawnParams; - spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - //WeaponInWorld = Cast(GetWorld()->SpawnActor(PrimaryWeapon, loc, rot, spawnParams)); - WeaponInWorld->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); - WeaponInWorld->Destroy(); - - //for some reason the spawning of the weapon is broken to the players hand so need to fix this. - - // potentially add a varibable to check if its a secondary or priamry weapon being picked up - // add this in the baseweaponclass variable - } - } - if(WeaponInWorld->IsA(ABaseWeaponClass::StaticClass())) - { - if(SecondaryWeapon) - { - UE_LOG(LogTemp, Display, TEXT("Secondary Weapon Picked up")); - - } - } -}*/ void AEndlessVendettaCharacter::Move(const FInputActionValue& Value) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index cf41bef6..20681db6 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -103,7 +103,6 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void TapFireCaller(); - protected: /** Called for movement input */ void Move(const FInputActionValue& Value); @@ -119,9 +118,6 @@ protected: void EquipSecondary(); - //Called from Player BluePrints - //UFUNCTION(BlueprintCallable, Category = "Weapons") - //void WeaponPickUpSystem(AActor* PickedUpWeapon); protected: // APawn interface @@ -133,6 +129,7 @@ public: USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; } /** Returns FirstPersonCameraComponent subobject **/ UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; } + }; diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index 0d14f19d..89e02d0a 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -22,21 +22,13 @@ void ABaseWeaponClass::BeginPlay() // Attempt to find the player character APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0); player = Cast(PlayerController->GetCharacter()); - if (PlayerController) + + for (UActorComponent* actorComp : player->GetComponentsByTag(UArrowComponent::StaticClass(), FName("GunStart"))) { - if (player) - { - UE_LOG(LogTemp, Display, TEXT("BeginPlay: Player found.")); - } - else - { - UE_LOG(LogTemp, Error, TEXT("BeginPlay: Player not found.")); - } - } - else - { - UE_LOG(LogTemp, Error, TEXT("BeginPlay: Player controller not found.")); + GunStartArrow = Cast(actorComp); + break; } + } // Called every frame @@ -47,20 +39,23 @@ void ABaseWeaponClass::Tick(float DeltaTime) void ABaseWeaponClass::TapFire() { + FTimerHandle timerHandle; FHitResult outHit; FVector traceStart; FVector traceEnd; - traceStart = player->GetActorLocation(); - traceEnd = traceStart + (player->GetActorForwardVector() * 50); - UE_LOG(LogTemp, Display, TEXT("World: %s"), *GetWorld()->GetName()); + traceStart = GunStartArrow->GetComponentLocation(); + traceEnd = traceStart + (player->GetActorForwardVector() * BulletDistance); FCollisionQueryParams collisionParams; + collisionParams.AddIgnoredActor(player); + collisionParams.AddIgnoredActor(this); + GetWorldTimerManager().SetTimer(timerHandle, 1 / FireRate, false, 1.0f); GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams); //Debug line to see where the trace hit - DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, true); + DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, true, 500.0f, 0U, 5.f); if (outHit.bBlockingHit) { - UE_LOG(LogTemp, Display, TEXT("Hit something")); + UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName()); + } - UE_LOG(LogTemp, Display, TEXT("BOOMBOOMBIMBAMBIM")); } diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index 2fc1219a..149d45d5 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "WeaponItemClass.h" +#include "Components/ArrowComponent.h" #include "BaseWeaponClass.generated.h" class AEndlessVendettaCharacter; @@ -47,7 +48,12 @@ public: UPROPERTY(VisibleAnywhere) ACharacter* player; - +private: + + UArrowComponent* GunStartArrow; + + UPROPERTY(EditAnywhere) + float BulletDistance; //Add HoldFire functionality after pistol is complete for holding fire for pistol and make it start spraying innacuratly.