Added Shotgun Functionality Firing

This commit is contained in:
Marcel Hara 2023-11-06 14:01:57 +00:00
parent 425ceb05d0
commit a790a4a790
2 changed files with 36 additions and 0 deletions

View File

@ -2,9 +2,42 @@
#include "ShotgunClass.h" #include "ShotgunClass.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"
#include "Engine/DamageEvents.h"
AShotgunClass::AShotgunClass() AShotgunClass::AShotgunClass()
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
} }
void AShotgunClass::Fire()
{
if(currentAmmoCount > 0)
{
traceStart = GunStartArrow->GetComponentLocation();
if (GetWorldTimerManager().IsTimerActive(timerHandle)) return;
for (int i = 0; i < 5; i++)
{
FVector newStartTrace = UKismetMathLibrary::RandomPointInBoundingBox(traceStart, FVector(10,10,10));
traceEnd = newStartTrace + (GunStartArrow->GetForwardVector() * BulletDistance);
GetWorld()->LineTraceSingleByChannel(outHit, newStartTrace, traceEnd, ECC_Visibility, collisionParams);
DrawDebugLine(this->GetWorld(), newStartTrace, traceEnd, FColor::Red , false, 100.f, 0U, 1.f);
currentAmmoCount --;
}
playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1);
GenerateRecoilVector();
ClickDetectionTimer();
bulletCountShoot += 1;
bStopShooting = false;
if (outHit.bBlockingHit)
{
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
}
else if(currentAmmoCount <= 0)
{
UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount);
}
}

View File

@ -18,4 +18,7 @@ public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AShotgunClass(); AShotgunClass();
protected:
virtual void Fire() override;
}; };