From a45b7488ba45dedb8449ed4e3e671d9f3db811aa Mon Sep 17 00:00:00 2001 From: MH261677 Date: Thu, 19 Oct 2023 17:38:18 +0100 Subject: [PATCH] Working weapon switching --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 +-- .../BaseWeapons/BP_BaseWeapon.uasset | 4 +-- .../Pistols/BP_BasePistolWeapon.uasset | 4 +-- .../BaseWeapons/WBP_AmmoCount.uasset | 4 +-- .../LevelPrototyping/Scenes/TutorialHit.umap | 4 +-- .../EndlessVendettaCharacter.cpp | 27 ++++++++++++------- .../EndlessVendettaCharacter.h | 2 +- .../WeaponSystem/BaseWeaponClass.cpp | 5 ++-- 8 files changed, 31 insertions(+), 23 deletions(-) diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index ef5cc606..1378ceef 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:dfeced37123c7e12907f8c5c3882aa970013d96167d07df1d71a464e2f91fd0d -size 42429 +oid sha256:2ffa922873f3999c8ef2d7ff492cedee047c6e06cc8b56c6ee9aaeab08d8fbad +size 42684 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/BP_BaseWeapon.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/BP_BaseWeapon.uasset index cac2db11..af5ea1b4 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:c5ee53e7d84e4e0a3a6941011ad8a3c2718afe0bad7e95cf23f7cc1063476f53 -size 124677 +oid sha256:5e1e829f4770985384af4baf7f94ed5089f11e12ec69b2ec09fb5f193a1ab960 +size 124465 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset index 206389d1..f54627fd 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2a94e9d1b1b74a330a53970bbb11f1357c02996a00a31d4bdafc5c9313759fb2 -size 49286 +oid sha256:5aebaef6e44e3ebd6edf9b98ada3bdc65e43a0e7372ac8545eee7d3f5f535e21 +size 125647 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/WBP_AmmoCount.uasset index b4d8011b..ff0850c9 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:dc183a9d9781ca6800fa345b6428f7bf41953180f79e74b96c894a33b9d789e9 -size 64773 +oid sha256:4aef926e64cc0bd15cd6df6c9683311954a37d3a4576cd79a564efe16ef7920d +size 64353 diff --git a/EndlessVendetta/Content/LevelPrototyping/Scenes/TutorialHit.umap b/EndlessVendetta/Content/LevelPrototyping/Scenes/TutorialHit.umap index 50e7b151..3ff2d458 100644 --- a/EndlessVendetta/Content/LevelPrototyping/Scenes/TutorialHit.umap +++ b/EndlessVendetta/Content/LevelPrototyping/Scenes/TutorialHit.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:57903d1174f13c4e930113e1f5aba86389d1568b4e42193474fec9da7cfd55aa -size 301943 +oid sha256:a81357c429cab843eb8ff42acc335aa7e0ee24d4d441286eb3d80b04a70b1231 +size 307063 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index b752c8e2..e3285c39 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -138,16 +138,19 @@ void AEndlessVendettaCharacter::Interact() QueryParams.AddIgnoredActor(this); FVector LT_Start = FirstPersonCameraComponent->GetComponentLocation(); FVector LT_End = LT_Start + (FirstPersonCameraComponent->GetForwardVector() * InteractionRange); + if(IsValid(PrimaryWeapon)) + { + QueryParams.AddIgnoredActor(PrimaryWeapon); + } + if(IsValid(SecondaryWeapon)) + { + QueryParams.AddIgnoredActor(SecondaryWeapon); + } if (!GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera, QueryParams)) return; - AActor* HitActor = OutHit.GetActor(); UE_LOG(LogTemp, Warning, TEXT("Hit actor: %s"), *HitActor->GetName()); IInteractionInterface* InteractableActor = Cast(HitActor); - if (InteractableActor) - { - InteractableActor->Interact(); - WeaponSwitcher(OutHit); - } + if (InteractableActor) InteractableActor->Interact(); } @@ -274,11 +277,15 @@ void AEndlessVendettaCharacter::EquipSecondary() SecondaryWeapon = Cast(SecondaryWeaponActor); } -void AEndlessVendettaCharacter::WeaponSwitcher(FHitResult Outhit) +void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit) { - if (IsValid(PrimaryWeapon)) PrimaryWeapon->Destroy(); - PrimaryWeapon = Cast(Outhit.GetActor()); - Outhit.GetActor()->Destroy(); + if (IsValid(PrimaryWeapon)) + { + EquipPrimary(); + } + PrimaryWeaponClass = Outhit->GetClass(); + Outhit->Destroy(); + EquipPrimary(); } //Calls the fire function in the baseWeaponClass diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 9c3468d9..a3d099ce 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -176,5 +176,5 @@ public: void EquipPrimary(); void EquipSecondary(); - void WeaponSwitcher(FHitResult Outhit); + void WeaponSwitcher(AActor* Outhit); }; diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index 503fd58b..74dac6e0 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -234,6 +234,7 @@ void ABaseWeaponClass::Interact() { if(!IsValid(this)) return; GLog->Log("Interact Called"); + endlessVendettaChar->WeaponSwitcher(this); } void ABaseWeaponClass::InteractPrompt() @@ -251,8 +252,8 @@ void ABaseWeaponClass::InteractPrompt() // { // endlessVendettaChar->EquipPrimary(); // } -// //HitActor = Cast(endlessVendettaChar->PrimaryWeaponClass); -// //endlessVendettaChar->PrimaryWeapon = Cast(HitActor); +// AActor* HitActor = Cast(endlessVendettaChar->PrimaryWeaponClass); +// endlessVendettaChar->PrimaryWeapon = Cast(HitActor); // }