Added Full Weapon Damage Drop Off To All Guns

This commit is contained in:
Marcel Hara 2023-11-06 17:21:34 +00:00
parent 34ef5c6e40
commit 783e7bd136
6 changed files with 32 additions and 17 deletions

View File

@ -183,8 +183,16 @@ void ABaseWeaponClass::Fire()
bStopShooting = false;
if (outHit.bBlockingHit)
{
if (outHit.Distance >= FMath::Floor(BulletDistance/2))
{
tempWeaponDamage = WeaponDamage / 2;
}
else
{
tempWeaponDamage = WeaponDamage;
}
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
}
else if(currentAmmoCount <= 0)

View File

@ -180,6 +180,7 @@ protected:
UArrowComponent* GunStartArrow;
bool bStopShooting = false;
UPROPERTY(VisibleAnywhere)
int tempWeaponDamage;
float originalMagnitude;

View File

@ -27,15 +27,6 @@ void AShotgunClass::Fire()
{
FVector newStartTrace = UKismetMathLibrary::RandomPointInBoundingBox(traceStart, ShotgunBulletSpread);
traceEnd = newStartTrace + (GunStartArrow->GetForwardVector() * BulletDistance);
if (outHit.Distance >= FMath::Floor(BulletDistance/1.5))
{
tempWeaponDamage /= 2;
GLog->Log("Bullet distance reached a quarter");
}
else
{
tempWeaponDamage = WeaponDamage;
}
GetWorld()->LineTraceSingleByChannel(outHit, newStartTrace, traceEnd, ECC_Visibility, collisionParams);
DrawDebugLine(this->GetWorld(), newStartTrace, traceEnd, FColor::Red , false, 100.f, 0U, 1.f);
currentAmmoCount --;
@ -47,8 +38,16 @@ void AShotgunClass::Fire()
bStopShooting = false;
if (outHit.bBlockingHit)
{
if (outHit.Distance >= FMath::Floor(BulletDistance/2))
{
tempWeaponDamage = WeaponDamage / 2;
}
else
{
tempWeaponDamage = WeaponDamage;
}
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
}
else if(currentAmmoCount <= 0)

View File

@ -58,9 +58,16 @@ void ASniperClass::Fire()
this->GetWorld()->GetTimerManager().SetTimer(SniperTimerHandle, this, &ASniperClass::StopFire, FireRate, false);
if (outHit.bBlockingHit)
{
UE_LOG(LogTemp, Display, TEXT("Hit: %s"), *outHit.GetActor()->GetName());
if (outHit.Distance >= FMath::Floor(BulletDistance/2))
{
tempWeaponDamage = WeaponDamage / 2;
}
else
{
tempWeaponDamage = WeaponDamage;
}
if (!Cast<AAICharacter>(outHit.GetActor())) return;
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(WeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
Cast<AAICharacter>(outHit.GetActor())->TakeDamage(tempWeaponDamage, FPointDamageEvent(), GetWorld()->GetFirstPlayerController(), this);
}
}
else if(currentAmmoCount <= 0)