use curve for adjusting damage over distance

This commit is contained in:
in0finite 2020-06-28 16:35:35 +02:00
parent ba4e10bb3a
commit bfdb8a5ba0
4 changed files with 34 additions and 3 deletions

View file

@ -97,6 +97,32 @@ MonoBehaviour:
vehicleSyncRate: 20
explosionForceMultiplier: 700
explosionChassisForceMultiplier: 11000
explosionDamageRadius: 7
explosionDamageOverDistanceCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: -1.8359536
outSlope: -1.8359536
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0.049225323
- serializedVersion: 3
time: 1
value: 0
inSlope: -0.15980668
outSlope: -0.15980668
tangentMode: 0
weightedMode: 0
inWeight: 0.08929417
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
explosionMassToDamageExponent: 1
explosionLeftoverPartsLifetime: 30
explosionLeftoverPartsMaxDepenetrationVelocity: 15
explosionLeftoverPartsMass: 100

View file

@ -24,6 +24,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
public float explosionForceMultiplier = 700f;
public float explosionChassisForceMultiplier = 11000f;
public float explosionDamageRadius = 7f;
public AnimationCurve explosionDamageOverDistanceCurve = AnimationCurve.Linear(0f, 1f, 1f, 0f);
[Range(0.1f, 3f)] public float explosionMassToDamageExponent = 1f;
public float explosionLeftoverPartsLifetime = 20f;

View file

@ -185,7 +185,10 @@ namespace SanAndreasUnity.Behaviours.Vehicles
// inflict damage to nearby objects
Damageable.InflictDamageToObjectsInArea(
explosionCenter, VehicleManager.Instance.explosionDamageRadius, Mathf.Pow(this.HandlingData.Mass, VehicleManager.Instance.explosionMassToDamageExponent));
explosionCenter,
VehicleManager.Instance.explosionDamageRadius,
Mathf.Pow(this.HandlingData.Mass, VehicleManager.Instance.explosionMassToDamageExponent),
VehicleManager.Instance.explosionDamageOverDistanceCurve);
// create explosion effect

View file

@ -44,7 +44,8 @@ namespace SanAndreasUnity.Utilities
}
}
public static void InflictDamageToObjectsInArea(Vector3 center, float radius, float damageAmount)
public static void InflictDamageToObjectsInArea(
Vector3 center, float radius, float damageAmount, AnimationCurve damageOverDistanceCurve)
{
Collider[] overlappingColliders = Physics.OverlapSphere(center, radius);
@ -95,7 +96,7 @@ namespace SanAndreasUnity.Utilities
// apply damage based on closest distance
float distance = closestPointDistance;
float distanceFactor = 1.0f - Mathf.Clamp01(distance / radius);
float distanceFactor = damageOverDistanceCurve.Evaluate(Mathf.Clamp01(distance / radius));
float damageAmountBasedOnDistance = damageAmount * distanceFactor;
F.RunExceptionSafe(() => damageable.Damage(new DamageInfo() { amount = damageAmountBasedOnDistance }));