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,9 +22,19 @@ public:
FVector_NetQuantize100 InitialVelocity; FVector_NetQuantize100 InitialVelocity;
UPROPERTY(EditAnywhere) 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; 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: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;

View File

@ -46,7 +46,9 @@ void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor,
{ {
if (OwnerCharacter->HasAuthority() && !bUseServerSideRewind) 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); Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit);
return; return;
} }

View File

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