Basic Shooting functionality fixed

Shooting now shoots a ray out and detects what object is being hit
This commit is contained in:
MARCEL HARA 2023-10-02 13:36:19 +01:00
parent c0cc7c4782
commit 5743e885e0
11 changed files with 57 additions and 144 deletions

Binary file not shown.

View File

@ -7,7 +7,7 @@
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "BountyClass.generated.h" #include "BountyClass.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedFirstCheckpoint) DECLARE_DYNAMIC_MULTICAST_DELEGATE(FCompletedFirstCheckpoint);
UCLASS() UCLASS()
class ENDLESSVENDETTA_API ABountyClass : public AActor class ENDLESSVENDETTA_API ABountyClass : public AActor

View File

@ -89,6 +89,7 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
//Weapon Shooting //Weapon Shooting
EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller); EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller);
EnhancedInputComponent->BindAction(HoldShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller);
} }
} }
@ -146,11 +147,9 @@ void AEndlessVendettaCharacter::EquipPrimary()
if (IsValid(SecondaryWeapon)) EquipSecondary(); 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; FActorSpawnParameters spawnParams;
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
@ -164,34 +163,6 @@ void AEndlessVendettaCharacter::EquipPrimary()
//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 //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<ABaseWeaponClass>(PrimaryWeaponActor); PrimaryWeapon = Cast<ABaseWeaponClass>(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<AActor>(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<ABaseWeaponClass>(PrimaryWeaponActor);
//
// }
// else if (IsValid(PrimaryWeapon))
// {
// PrimaryWeapon->Destroy();
// bHasRifle = false;
// }
} }
void AEndlessVendettaCharacter::EquipSecondary() void AEndlessVendettaCharacter::EquipSecondary()
@ -206,11 +177,9 @@ void AEndlessVendettaCharacter::EquipSecondary()
if (IsValid(PrimaryWeapon)) EquipPrimary(); 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; FActorSpawnParameters spawnParams;
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
@ -221,24 +190,6 @@ void AEndlessVendettaCharacter::EquipSecondary()
SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor); SecondaryWeapon = Cast<ABaseWeaponClass>(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<AActor>(SecondaryWeaponClass, spawnParams);
// SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint"));
// SecondaryWeapon = Cast<ABaseWeaponClass>(SecondaryWeaponActor);
// }
// else if (IsValid(SecondaryWeapon))
// {
// SecondaryWeapon->Destroy();
// bHasRifle = false;
// }
} }
@ -246,48 +197,12 @@ void AEndlessVendettaCharacter::EquipSecondary()
void AEndlessVendettaCharacter::TapFireCaller() void AEndlessVendettaCharacter::TapFireCaller()
{ {
UE_LOG(LogTemp, Warning, TEXT("Tap Fire")); UE_LOG(LogTemp, Warning, TEXT("Tap Fire"));
// if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon)) if (IsValid(PrimaryWeapon) || IsValid(SecondaryWeapon))
// {
// PrimaryWeaponClass.GetDefaultObject()->TapFire();
// }
}
//POTENTIAL PICKUP SYSTEM NEEDS CHANGING BUT YES
//Called from Player BluePrints
/*void AEndlessVendettaCharacter::WeaponPickUpSystem(AActor* PickedUpWeapon)
{ {
ABaseWeaponClass* WeaponInWorld = Cast<ABaseWeaponClass>(PickedUpWeapon); PrimaryWeapon->TapFire();
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<ABaseWeaponClass>(GetWorld()->SpawnActor<AActor>(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) void AEndlessVendettaCharacter::Move(const FInputActionValue& Value)

View File

@ -103,7 +103,6 @@ public:
UFUNCTION(BlueprintCallable, Category = "Weapons") UFUNCTION(BlueprintCallable, Category = "Weapons")
void TapFireCaller(); void TapFireCaller();
protected: protected:
/** Called for movement input */ /** Called for movement input */
void Move(const FInputActionValue& Value); void Move(const FInputActionValue& Value);
@ -119,9 +118,6 @@ protected:
void EquipSecondary(); void EquipSecondary();
//Called from Player BluePrints
//UFUNCTION(BlueprintCallable, Category = "Weapons")
//void WeaponPickUpSystem(AActor* PickedUpWeapon);
protected: protected:
// APawn interface // APawn interface
@ -134,5 +130,6 @@ public:
/** Returns FirstPersonCameraComponent subobject **/ /** Returns FirstPersonCameraComponent subobject **/
UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; } UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; }
}; };

View File

@ -22,21 +22,13 @@ void ABaseWeaponClass::BeginPlay()
// Attempt to find the player character // Attempt to find the player character
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0); APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);
player = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter()); player = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter());
if (PlayerController)
for (UActorComponent* actorComp : player->GetComponentsByTag(UArrowComponent::StaticClass(), FName("GunStart")))
{ {
if (player) GunStartArrow = Cast<UArrowComponent>(actorComp);
{ break;
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."));
} }
} }
// Called every frame // Called every frame
@ -47,20 +39,23 @@ void ABaseWeaponClass::Tick(float DeltaTime)
void ABaseWeaponClass::TapFire() void ABaseWeaponClass::TapFire()
{ {
FTimerHandle timerHandle;
FHitResult outHit; FHitResult outHit;
FVector traceStart; FVector traceStart;
FVector traceEnd; FVector traceEnd;
traceStart = player->GetActorLocation(); traceStart = GunStartArrow->GetComponentLocation();
traceEnd = traceStart + (player->GetActorForwardVector() * 50); traceEnd = traceStart + (player->GetActorForwardVector() * BulletDistance);
UE_LOG(LogTemp, Display, TEXT("World: %s"), *GetWorld()->GetName());
FCollisionQueryParams collisionParams; FCollisionQueryParams collisionParams;
collisionParams.AddIgnoredActor(player);
collisionParams.AddIgnoredActor(this);
GetWorldTimerManager().SetTimer(timerHandle, 1 / FireRate, false, 1.0f);
GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams); GetWorld()->LineTraceSingleByChannel(outHit, traceStart, traceEnd, ECC_Visibility, collisionParams);
//Debug line to see where the trace hit //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) 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"));
} }

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "WeaponItemClass.h" #include "WeaponItemClass.h"
#include "Components/ArrowComponent.h"
#include "BaseWeaponClass.generated.h" #include "BaseWeaponClass.generated.h"
class AEndlessVendettaCharacter; class AEndlessVendettaCharacter;
@ -47,7 +48,12 @@ public:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
ACharacter* player; 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. //Add HoldFire functionality after pistol is complete for holding fire for pistol and make it start spraying innacuratly.