Skip to content

Commit 9c07243

Browse files
committed
Added damage falloff at range
1 parent 98bb8c8 commit 9c07243

File tree

8 files changed

+184
-2
lines changed

8 files changed

+184
-2
lines changed
Binary file not shown.
Binary file not shown.

PluginExample/Plugins/MultiplayerFPS/Content/ParticleEffects/P_BloodSplash.uasset renamed to PluginExample/Plugins/MultiplayerFPS/Content/ParticleEffects/P_blood_splash_02.uasset

319 KB
Binary file not shown.

PluginExample/Plugins/MultiplayerFPS/MultiplayerFPS.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "2.0",
4+
"VersionName": "2.01",
55
"FriendlyName": "Multiplayer FPS",
66
"Description": "This plugin allows you to create a multiplayer first person shooter with ease.",
77
"Category": "Multiplayer FPS",

PluginExample/Plugins/MultiplayerFPS/Source/MultiplayerFPS/Private/MultiplayerGun.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Engine/World.h"
1616
#include "Engine/Engine.h"
1717
#include "Engine/OverlapResult.h"
18+
#include "Algo/Reverse.h"
1819

1920
// Sets default values
2021
AMultiplayerGun::AMultiplayerGun()
@@ -136,6 +137,8 @@ AMultiplayerGun::AMultiplayerGun()
136137
PercentageOfOverheatToSpawnSmoke = 0.75f;
137138
BulletsShotForSmokeEffect = 0;
138139
BulletHitMode = 0;
140+
InterpolateDamageBetweenRanges = true;
141+
PrintDistanceTraveled = false;
139142
BulletHitModeDelay = 0.0f;
140143
FireControllerVibrationTag = "Fire";
141144
BulletHitControllerVibrationTag = "Hit";
@@ -858,6 +861,47 @@ void AMultiplayerGun::Fire()
858861
DamageToApply = DefaultDamage;
859862
}
860863

864+
float DistanceTraveled = (FireLocation - Hit.ImpactPoint).Size();
865+
866+
if (PrintDistanceTraveled == true)
867+
{
868+
PrintDistanceTraved_BP(DistanceTraveled);
869+
}
870+
871+
if (DamageFalloffMultiplierAtRange.Num() > 0)
872+
{
873+
TArray<float> Distances;
874+
TArray<float> Damages;
875+
876+
DamageFalloffMultiplierAtRange.GenerateKeyArray(Distances);
877+
DamageFalloffMultiplierAtRange.GenerateValueArray(Damages);
878+
879+
Algo::Reverse(Distances);
880+
Algo::Reverse(Damages);
881+
882+
bool AppliedDamageFalloff = false;
883+
884+
for (int32 Index = 0; Index != Distances.Num(); ++Index)
885+
{
886+
if (Distances.IsValidIndex(Index) && AppliedDamageFalloff == false)
887+
{
888+
if (DistanceTraveled >= Distances[Index])
889+
{
890+
if (Index != 0 && InterpolateDamageBetweenRanges == true)
891+
{
892+
DamageToApply *= UKismetMathLibrary::Ease(Damages[Index], Damages[Index - 1], UKismetMathLibrary::MapRangeClamped(DistanceTraveled, Distances[Index], Distances[Index -1], 0.0, 1.0), EEasingFunc::Linear);
893+
}
894+
else
895+
{
896+
DamageToApply *= Damages[Index];
897+
}
898+
899+
AppliedDamageFalloff = true;
900+
}
901+
}
902+
}
903+
}
904+
861905
if (LaunchPhysicsObjects == true && LaunchObjectStrength > 0)
862906
{
863907
if (UPrimitiveComponent* HitComponent = Hit.GetComponent())
@@ -1467,6 +1511,10 @@ void AMultiplayerGun::SpawnProjectile_Implementation(FVector FireLocation, FRota
14671511
SpawnedProjectile->SetBulletHitModeDelay(BulletHitModeDelay);
14681512
SpawnedProjectile->SetExplosiveDoFullDamage(ExplosiveDoFullDamage);
14691513
SpawnedProjectile->SetExplosiveCollisionChannel(CollisionChannel);
1514+
SpawnedProjectile->SetDamageFalloffMultiplierAtRange(DamageFalloffMultiplierAtRange);
1515+
SpawnedProjectile->SetInterpolateDamageBetweenRanges(InterpolateDamageBetweenRanges);
1516+
SpawnedProjectile->SetPrintDistanceTraveled(PrintDistanceTraveled);
1517+
SpawnedProjectile->SetFireLocation(FireLocation);
14701518
SpawnedProjectile->SetHitDirection(TraceDirection);
14711519
SpawnedProjectile->SetDefaultHitEffect(DefaultHitEffect);
14721520
SpawnedProjectile->SetHitEffects(HitEffects);

PluginExample/Plugins/MultiplayerFPS/Source/MultiplayerFPS/Private/MultiplayerProjectile.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ AMultiplayerProjectile::AMultiplayerProjectile()
3737
DefaultDamage = 35.0f;
3838
ExplosiveDamageRadius = 500.0f;
3939
ExplosiveDoFullDamage = false;
40+
InterpolateDamageBetweenRanges = true;
41+
PrintDistanceTraveled = false;
4042
BulletHitMode = 0;
4143
BulletHitModeDelay = 0.0f;
4244
HitEffectScale = FVector(1.0f, 1.0f, 1.0f);
@@ -161,6 +163,47 @@ void AMultiplayerProjectile::RegisterHit_Implementation(const FHitResult& Hit)
161163
{
162164
DamageToApply = DefaultDamage;
163165
}
166+
167+
float DistanceTraveled = (FireLocation - Hit.ImpactPoint).Size();
168+
169+
if (PrintDistanceTraveled == true)
170+
{
171+
PrintDistanceTraved_BP(DistanceTraveled);
172+
}
173+
174+
if (DamageFalloffMultiplierAtRange.Num() > 0)
175+
{
176+
TArray<float> Distances;
177+
TArray<float> Damages;
178+
179+
DamageFalloffMultiplierAtRange.GenerateKeyArray(Distances);
180+
DamageFalloffMultiplierAtRange.GenerateValueArray(Damages);
181+
182+
Algo::Reverse(Distances);
183+
Algo::Reverse(Damages);
184+
185+
bool AppliedDamageFalloff = false;
186+
187+
for (int32 Index = 0; Index != Distances.Num(); ++Index)
188+
{
189+
if (Distances.IsValidIndex(Index) && AppliedDamageFalloff == false)
190+
{
191+
if (DistanceTraveled >= Distances[Index])
192+
{
193+
if (Index != 0 && InterpolateDamageBetweenRanges == true)
194+
{
195+
DamageToApply *= UKismetMathLibrary::Ease(Damages[Index], Damages[Index - 1], UKismetMathLibrary::MapRangeClamped(DistanceTraveled, Distances[Index], Distances[Index -1], 0.0, 1.0), EEasingFunc::Linear);
196+
}
197+
else
198+
{
199+
DamageToApply *= Damages[Index];
200+
}
201+
202+
AppliedDamageFalloff = true;
203+
}
204+
}
205+
}
206+
}
164207

165208
if (LaunchPhysicsObjects == true && LaunchObjectStrength > 0)
166209
{
@@ -752,6 +795,46 @@ TEnumAsByte<ECollisionChannel> AMultiplayerProjectile::GetExplosiveCollisionChan
752795
return ExplosiveCollisionChannel;
753796
}
754797

798+
void AMultiplayerProjectile::SetDamageFalloffMultiplierAtRange(TMap<float, float> NewDamageFalloffMultiplierAtRange)
799+
{
800+
DamageFalloffMultiplierAtRange = NewDamageFalloffMultiplierAtRange;
801+
}
802+
803+
TMap<float, float> AMultiplayerProjectile::GetDamageFalloffMultiplierAtRange()
804+
{
805+
return DamageFalloffMultiplierAtRange;
806+
}
807+
808+
void AMultiplayerProjectile::SetInterpolateDamageBetweenRanges(bool NewInterpolateDamageBetweenRanges)
809+
{
810+
InterpolateDamageBetweenRanges = NewInterpolateDamageBetweenRanges;
811+
}
812+
813+
bool AMultiplayerProjectile::GetInterpolateDamageBetweenRanges()
814+
{
815+
return InterpolateDamageBetweenRanges;
816+
}
817+
818+
void AMultiplayerProjectile::SetPrintDistanceTraveled(bool NewPrintDistanceTraveled)
819+
{
820+
PrintDistanceTraveled = NewPrintDistanceTraveled;
821+
}
822+
823+
bool AMultiplayerProjectile::GetPrintDistanceTraveled()
824+
{
825+
return PrintDistanceTraveled;
826+
}
827+
828+
void AMultiplayerProjectile::SetFireLocation(FVector NewFireLocation)
829+
{
830+
FireLocation = NewFireLocation;
831+
}
832+
833+
FVector AMultiplayerProjectile::GetFireLocation()
834+
{
835+
return FireLocation;
836+
}
837+
755838
void AMultiplayerProjectile::SetHitDirection(FVector NewHitDirection)
756839
{
757840
HitDirection = NewHitDirection;

PluginExample/Plugins/MultiplayerFPS/Source/MultiplayerFPS/Public/MultiplayerGun.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,21 @@ class MULTIPLAYERFPS_API AMultiplayerGun : public AInteractableItem
644644
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "0 = just apply damage, 1 = apply damage and execute ExecuteHitFunction(), 2 = just execute ExecuteHitFunction(), to use this override the ExecuteHitFunction() or add event ExecuteHitFunction, for projectiles you will need to define this function in the projectile, this function only runs on server", ClampMin = 0, ClampMax = 2))
645645
int BulletHitMode;
646646

647+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "The first float is the distance traveled and the second float is the damage multiplier at that range, values above 1 do more damage, does not apply to explosives"))
648+
TMap<float, float> DamageFalloffMultiplierAtRange;
649+
650+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "Only applies if DamageFalloffMultiplierAtRange has 2 or more values, if the target distance is in between 2 distances in the DamageFalloffMultiplierAtRange variable the damage will also be in between the 2 damages in the DamageFalloffMultiplierAtRange variable"))
651+
bool InterpolateDamageBetweenRanges;
652+
653+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "This will print a string showing how far the bullet went"))
654+
bool PrintDistanceTraveled;
655+
656+
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Functions")
657+
void PrintDistanceTraved_BP(float Distance);
658+
647659
UPROPERTY(BlueprintReadWrite, Replicated, Category = "Variables")
648660
bool WasPickedup;
649-
661+
650662
UPROPERTY()
651663
int AmountOfTimesPickedup;
652664

PluginExample/Plugins/MultiplayerFPS/Source/MultiplayerFPS/Public/MultiplayerProjectile.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@ class MULTIPLAYERFPS_API AMultiplayerProjectile : public AActor
187187
UFUNCTION(BlueprintCallable, Category = "Functions")
188188
virtual TEnumAsByte<ECollisionChannel> GetExplosiveCollisionChannel();
189189

190+
UFUNCTION(BlueprintCallable, Category = "Functions")
191+
virtual void SetDamageFalloffMultiplierAtRange(TMap<float, float> NewDamageFalloffMultiplierAtRange);
192+
193+
UFUNCTION(BlueprintCallable, Category = "Functions")
194+
virtual TMap<float, float> GetDamageFalloffMultiplierAtRange();
195+
196+
UFUNCTION(BlueprintCallable, Category = "Functions")
197+
virtual void SetInterpolateDamageBetweenRanges(bool NewInterpolateDamageBetweenRanges);
198+
199+
UFUNCTION(BlueprintCallable, Category = "Functions")
200+
virtual bool GetInterpolateDamageBetweenRanges();
201+
202+
UFUNCTION(BlueprintCallable, Category = "Functions")
203+
virtual void SetPrintDistanceTraveled(bool NewPrintDistanceTraveled);
204+
205+
UFUNCTION(BlueprintCallable, Category = "Functions")
206+
virtual bool GetPrintDistanceTraveled();
207+
208+
UFUNCTION(BlueprintCallable, Category = "Functions")
209+
virtual void SetFireLocation(FVector NewFireLocation);
210+
211+
UFUNCTION(BlueprintCallable, Category = "Functions")
212+
virtual FVector GetFireLocation();
213+
190214
UFUNCTION(BlueprintCallable, Category = "Functions")
191215
virtual void SetHitDirection(FVector NewHitDirection);
192216

@@ -356,6 +380,21 @@ class MULTIPLAYERFPS_API AMultiplayerProjectile : public AActor
356380
UPROPERTY(BlueprintReadOnly, Category = "Damage")
357381
TEnumAsByte<ECollisionChannel> ExplosiveCollisionChannel;
358382

383+
UPROPERTY(BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "The first float is the distance traveled and the second float is the damage multiplier at that range, values above 1 do more damage, does not apply to explosives"))
384+
TMap<float, float> DamageFalloffMultiplierAtRange;
385+
386+
UPROPERTY(BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "Only applies if DamageFalloffMultiplierAtRange has 2 or more values, if the target distance is in between 2 distances in the DamageFalloffMultiplierAtRange variable the damage will also be in between the 2 damages in the DamageFalloffMultiplierAtRange variable"))
387+
bool InterpolateDamageBetweenRanges;
388+
389+
UPROPERTY(BlueprintReadWrite, Category = "Damage", meta = (Tooltip = "This will print a string showing how far the bullet went"))
390+
bool PrintDistanceTraveled;
391+
392+
UPROPERTY(BlueprintReadWrite, Category = "Damage")
393+
FVector FireLocation;
394+
395+
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Functions")
396+
void PrintDistanceTraved_BP(float Distance);
397+
359398
UPROPERTY(BlueprintReadWrite, Category = "Variables")
360399
FVector HitDirection;
361400

0 commit comments

Comments
 (0)