Working weapon switching

This commit is contained in:
MH261677 2023-10-19 17:38:18 +01:00
parent 6c1c5ca12e
commit a45b7488ba
8 changed files with 31 additions and 23 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:dfeced37123c7e12907f8c5c3882aa970013d96167d07df1d71a464e2f91fd0d oid sha256:2ffa922873f3999c8ef2d7ff492cedee047c6e06cc8b56c6ee9aaeab08d8fbad
size 42429 size 42684

Binary file not shown.

View File

@ -138,16 +138,19 @@ void AEndlessVendettaCharacter::Interact()
QueryParams.AddIgnoredActor(this); QueryParams.AddIgnoredActor(this);
FVector LT_Start = FirstPersonCameraComponent->GetComponentLocation(); FVector LT_Start = FirstPersonCameraComponent->GetComponentLocation();
FVector LT_End = LT_Start + (FirstPersonCameraComponent->GetForwardVector() * InteractionRange); 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; if (!GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera, QueryParams)) return;
AActor* HitActor = OutHit.GetActor(); AActor* HitActor = OutHit.GetActor();
UE_LOG(LogTemp, Warning, TEXT("Hit actor: %s"), *HitActor->GetName()); UE_LOG(LogTemp, Warning, TEXT("Hit actor: %s"), *HitActor->GetName());
IInteractionInterface* InteractableActor = Cast<IInteractionInterface>(HitActor); IInteractionInterface* InteractableActor = Cast<IInteractionInterface>(HitActor);
if (InteractableActor) if (InteractableActor) InteractableActor->Interact();
{
InteractableActor->Interact();
WeaponSwitcher(OutHit);
}
} }
@ -274,11 +277,15 @@ void AEndlessVendettaCharacter::EquipSecondary()
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor); SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
} }
void AEndlessVendettaCharacter::WeaponSwitcher(FHitResult Outhit) void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
{ {
if (IsValid(PrimaryWeapon)) PrimaryWeapon->Destroy(); if (IsValid(PrimaryWeapon))
PrimaryWeapon = Cast<ABaseWeaponClass>(Outhit.GetActor()); {
Outhit.GetActor()->Destroy(); EquipPrimary();
}
PrimaryWeaponClass = Outhit->GetClass();
Outhit->Destroy();
EquipPrimary();
} }
//Calls the fire function in the baseWeaponClass //Calls the fire function in the baseWeaponClass

View File

@ -176,5 +176,5 @@ public:
void EquipPrimary(); void EquipPrimary();
void EquipSecondary(); void EquipSecondary();
void WeaponSwitcher(FHitResult Outhit); void WeaponSwitcher(AActor* Outhit);
}; };

View File

@ -234,6 +234,7 @@ void ABaseWeaponClass::Interact()
{ {
if(!IsValid(this)) return; if(!IsValid(this)) return;
GLog->Log("Interact Called"); GLog->Log("Interact Called");
endlessVendettaChar->WeaponSwitcher(this);
} }
void ABaseWeaponClass::InteractPrompt() void ABaseWeaponClass::InteractPrompt()
@ -251,8 +252,8 @@ void ABaseWeaponClass::InteractPrompt()
// { // {
// endlessVendettaChar->EquipPrimary(); // endlessVendettaChar->EquipPrimary();
// } // }
// //HitActor = Cast<ABaseWeaponClass>(endlessVendettaChar->PrimaryWeaponClass); // AActor* HitActor = Cast<ABaseWeaponClass>(endlessVendettaChar->PrimaryWeaponClass);
// //endlessVendettaChar->PrimaryWeapon = Cast<ABaseWeaponClass>(HitActor); // endlessVendettaChar->PrimaryWeapon = Cast<ABaseWeaponClass>(HitActor);
// } // }