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
oid sha256:dfeced37123c7e12907f8c5c3882aa970013d96167d07df1d71a464e2f91fd0d
size 42429
oid sha256:2ffa922873f3999c8ef2d7ff492cedee047c6e06cc8b56c6ee9aaeab08d8fbad
size 42684

Binary file not shown.

View File

@ -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<IInteractionInterface>(HitActor);
if (InteractableActor)
{
InteractableActor->Interact();
WeaponSwitcher(OutHit);
}
if (InteractableActor) InteractableActor->Interact();
}
@ -274,11 +277,15 @@ void AEndlessVendettaCharacter::EquipSecondary()
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
}
void AEndlessVendettaCharacter::WeaponSwitcher(FHitResult Outhit)
void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
{
if (IsValid(PrimaryWeapon)) PrimaryWeapon->Destroy();
PrimaryWeapon = Cast<ABaseWeaponClass>(Outhit.GetActor());
Outhit.GetActor()->Destroy();
if (IsValid(PrimaryWeapon))
{
EquipPrimary();
}
PrimaryWeaponClass = Outhit->GetClass();
Outhit->Destroy();
EquipPrimary();
}
//Calls the fire function in the baseWeaponClass

View File

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

View File

@ -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<ABaseWeaponClass>(endlessVendettaChar->PrimaryWeaponClass);
// //endlessVendettaChar->PrimaryWeapon = Cast<ABaseWeaponClass>(HitActor);
// AActor* HitActor = Cast<ABaseWeaponClass>(endlessVendettaChar->PrimaryWeaponClass);
// endlessVendettaChar->PrimaryWeapon = Cast<ABaseWeaponClass>(HitActor);
// }