Added Appropriate Weapon Switching for Both Primary and Secondary
This commit is contained in:
parent
9da3eed21b
commit
065984e21b
@ -278,7 +278,6 @@ void AEndlessVendettaCharacter::EquipPrimary()
|
|||||||
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||||
FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false);
|
FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false);
|
||||||
|
|
||||||
if (bIsReloading) return;
|
if (bIsReloading) return;
|
||||||
if (IsValid(PrimaryWeapon))
|
if (IsValid(PrimaryWeapon))
|
||||||
{
|
{
|
||||||
@ -292,31 +291,28 @@ void AEndlessVendettaCharacter::EquipPrimary()
|
|||||||
GLog->Log("Primary Weapon Put Away");
|
GLog->Log("Primary Weapon Put Away");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(bIsWeaponPickedUp)
|
||||||
|
{
|
||||||
|
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||||
|
bIsWeaponPickedUp = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsValid(SecondaryWeapon)) EquipSecondary();
|
if (IsValid(SecondaryWeapon)) EquipSecondary();
|
||||||
|
|
||||||
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
||||||
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
|
if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;
|
||||||
|
|
||||||
|
bHasRifle = true;
|
||||||
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
if(!bIsPrimaryWeaponCreated)
|
||||||
|
|
||||||
//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
|
|
||||||
|
|
||||||
if(!IsValid(PrimaryWeapon))
|
|
||||||
{
|
{
|
||||||
bHasRifle = true;
|
//Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass
|
||||||
if(!bIsPrimaryWeaponCreated)
|
//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
|
||||||
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||||
PrimaryWeapon->SetActorHiddenInGame(false);
|
PrimaryWeapon->SetActorHiddenInGame(false);
|
||||||
bIsPrimaryWeaponCreated = true;
|
bIsPrimaryWeaponCreated = true;
|
||||||
}
|
|
||||||
//UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden());
|
|
||||||
GLog->Log("Primary Weapon Equipped");
|
|
||||||
}
|
}
|
||||||
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
|
||||||
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
PrimaryWeapon = Cast<ABaseWeaponClass>(PrimaryWeaponActor);
|
||||||
@ -345,6 +341,12 @@ void AEndlessVendettaCharacter::EquipSecondary()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(bIsWeaponPickedUp)
|
||||||
|
{
|
||||||
|
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
|
||||||
|
bIsWeaponPickedUp = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsValid(PrimaryWeapon)) EquipPrimary();
|
if (IsValid(PrimaryWeapon)) EquipPrimary();
|
||||||
|
|
||||||
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;
|
||||||
@ -372,13 +374,28 @@ void AEndlessVendettaCharacter::EquipSecondary()
|
|||||||
|
|
||||||
void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
|
void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
|
||||||
{
|
{
|
||||||
if (IsValid(PrimaryWeapon))
|
if(Outhit->ActorHasTag("PrimaryWeapon"))
|
||||||
{
|
{
|
||||||
|
if (IsValid(PrimaryWeapon))
|
||||||
|
{
|
||||||
|
EquipPrimary();
|
||||||
|
}
|
||||||
|
bIsWeaponPickedUp = true;
|
||||||
|
PrimaryWeaponClass = Outhit->GetClass();
|
||||||
|
Outhit->Destroy();
|
||||||
EquipPrimary();
|
EquipPrimary();
|
||||||
}
|
}
|
||||||
PrimaryWeaponClass = Outhit->GetClass();
|
if(Outhit->ActorHasTag("SecondaryWeapon"))
|
||||||
Outhit->Destroy();
|
{
|
||||||
EquipPrimary();
|
if (IsValid(SecondaryWeapon))
|
||||||
|
{
|
||||||
|
EquipSecondary();
|
||||||
|
}
|
||||||
|
bIsWeaponPickedUp = true;
|
||||||
|
SecondaryWeaponClass = Outhit->GetClass();
|
||||||
|
Outhit->Destroy();
|
||||||
|
EquipSecondary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calls the fire function in the baseWeaponClass
|
//Calls the fire function in the baseWeaponClass
|
||||||
|
@ -85,6 +85,7 @@ public:
|
|||||||
AActor* SecondaryWeaponActor;
|
AActor* SecondaryWeaponActor;
|
||||||
bool bIsPrimaryWeaponCreated = false;
|
bool bIsPrimaryWeaponCreated = false;
|
||||||
bool bIsSecondaryWeaponCreated = false;
|
bool bIsSecondaryWeaponCreated = false;
|
||||||
|
bool bIsWeaponPickedUp = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user