mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-14 16:27:19 +00:00
inflict damage to nearby objects
This commit is contained in:
parent
b2af2ade90
commit
9678faa18a
3 changed files with 37 additions and 1 deletions
|
@ -182,6 +182,10 @@ namespace SanAndreasUnity.Behaviours.Vehicles
|
|||
this.HandlingData.Mass * 0.8f);
|
||||
}
|
||||
|
||||
// inflict damage to nearby objects
|
||||
|
||||
Damageable.InflictDamageToObjectsInArea(explosionCenter, 6f, this.HandlingData.Mass);
|
||||
|
||||
// create explosion effect
|
||||
|
||||
GameObject explosionGo = Object.Instantiate(VehicleManager.Instance.explosionPrefab, this.transform.position, this.transform.rotation);
|
||||
|
|
|
@ -44,6 +44,38 @@ namespace SanAndreasUnity.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
public static void InflictDamageToObjectsInArea(Vector3 center, float radius, float damageAmount)
|
||||
{
|
||||
Collider[] colliders = Physics.OverlapSphere(center, radius);
|
||||
|
||||
var damagables = new HashSet<Damageable>();
|
||||
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
var damagable = collider.GetComponentInParent<Damageable>();
|
||||
if (damagable != null && !damagables.Contains(damagable))
|
||||
{
|
||||
damagables.Add(damagable);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var damageable in damagables)
|
||||
{
|
||||
//Collider collider = pair.Value;
|
||||
|
||||
//Vector3 closestPointOnCollider = collider.ClosestPoint(center);
|
||||
//float distanceToPointOnCollider = Vector3.Distance(center, closestPointOnCollider);
|
||||
//float distanceToCollider = Vector3.Distance(center, collider.transform.position);
|
||||
|
||||
float distance = Vector3.Distance(center, damageable.transform.position);
|
||||
float distanceFactor = 1.0f - Mathf.Clamp01(distance / radius);
|
||||
float damageAmountBasedOnDistance = damageAmount * distanceFactor;
|
||||
|
||||
F.RunExceptionSafe(() => damageable.Damage(new DamageInfo() { amount = damageAmountBasedOnDistance }));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e2abbfcf853f5c7b3a5fe891df0b08ffa396afd4
|
||||
Subproject commit 95287f6ab37fe3261d7a517551633ee4b329ab2e
|
Loading…
Reference in a new issue