212 - Projectile Head Shots

This commit is contained in:
Kingsmedia 2022-05-29 14:35:57 +02:00
parent 0d5eb1b16d
commit 9b45b23dfd
9 changed files with 18 additions and 4 deletions

Binary file not shown.

View File

@ -22,10 +22,20 @@ public:
FVector_NetQuantize100 InitialVelocity;
UPROPERTY(EditAnywhere)
float InitialSpeed = 15000;
float InitialSpeed = 25000;
// SSR will get Damage directly from the weapon
// Non SSR, Damage will be set from the weapon
// Only set this for Grenades and Rockets
UPROPERTY(EditAnywhere)
float Damage = 20.f;
// SSR will get Damage directly from the weapon
// Non SSR, Damage will be set from the weapon
// Doesn't matter for Grenades and rockets
UPROPERTY(EditAnywhere)
float HeadShotDamage = 40.f;
protected:
virtual void BeginPlay() override;
void StartDestroyTimer();

View File

@ -46,7 +46,9 @@ void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor,
{
if (OwnerCharacter->HasAuthority() && !bUseServerSideRewind)
{
UGameplayStatics::ApplyDamage(OtherActor, Damage, OwnerController, this, UDamageType::StaticClass());
const float DamageToCause = Hit.BoneName.ToString() == FString("head") ? HeadShotDamage : Damage;
UGameplayStatics::ApplyDamage(OtherActor, DamageToCause, OwnerController, this, UDamageType::StaticClass());
Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit);
return;
}

View File

@ -17,8 +17,8 @@ void AProjectileWeapon::Fire(const FVector& HitTarget)
{
FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh());
// From muzzle flash socket to hit location from TraceUnderCrosshairs
FVector ToTarget = HitTarget - SocketTransform.GetLocation();
FRotator TargetRotation = ToTarget.Rotation();
const FVector ToTarget = HitTarget - SocketTransform.GetLocation();
const FRotator TargetRotation = ToTarget.Rotation();
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = GetOwner();
@ -34,6 +34,7 @@ void AProjectileWeapon::Fire(const FVector& HitTarget)
SpawnedProjectile = World->SpawnActor<AProjectile>(ProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
SpawnedProjectile->bUseServerSideRewind = false;
SpawnedProjectile->Damage = Damage;
SpawnedProjectile->HeadShotDamage = HeadShotDamage;
}
else // Server, not locally controlled - spawn non-replicated projectile, SSR
{
@ -64,6 +65,7 @@ void AProjectileWeapon::Fire(const FVector& HitTarget)
SpawnedProjectile = World->SpawnActor<AProjectile>(ProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams);
SpawnedProjectile->bUseServerSideRewind = false;
SpawnedProjectile->Damage = Damage;
SpawnedProjectile->HeadShotDamage = HeadShotDamage;
}
}
}