cleanup code

This commit is contained in:
in0finite 2020-07-01 19:25:59 +02:00
parent 395bcdcf4b
commit 2e0108d662
3 changed files with 9 additions and 22 deletions

View file

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

View file

@ -146,13 +146,10 @@ namespace SanAndreasUnity.Behaviours.Vehicles
Object.Destroy(this.gameObject); Object.Destroy(this.gameObject);
// detach vehicle parts and apply explosion force on them // detach vehicle parts
string[] startingNames = new string[] { "door_", "wheel_", "bonnet_", "boot_", "windscreen_", "exhaust_" }; string[] startingNames = new string[] { "door_", "wheel_", "bonnet_", "boot_", "windscreen_", "exhaust_" };
Vector3 explosionCenter = this.transform.position;
float explosionForce = Mathf.Sqrt(this.HandlingData.Mass) * VehicleManager.Instance.explosionForceMultiplier;
float explosionRadius = 10f;
foreach (var frame in _frames) foreach (var frame in _frames)
{ {
if (!frame.gameObject.activeInHierarchy) if (!frame.gameObject.activeInHierarchy)
@ -161,8 +158,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
if (!startingNames.Any(n => frame.gameObject.name.StartsWith(n))) if (!startingNames.Any(n => frame.gameObject.name.StartsWith(n)))
continue; continue;
DetachFrameDuringExplosion( DetachFrameDuringExplosion(frame, VehicleManager.Instance.explosionLeftoverPartsMass);
frame, explosionCenter, explosionForce, explosionRadius, VehicleManager.Instance.explosionLeftoverPartsMass);
} }
// chassis need to be handled after all other objects are detached, because chassis can sometimes // chassis need to be handled after all other objects are detached, because chassis can sometimes
@ -176,24 +172,19 @@ namespace SanAndreasUnity.Behaviours.Vehicles
} }
else else
{ {
DetachFrameDuringExplosion( DetachFrameDuringExplosion(chassisFrame, this.HandlingData.Mass * 0.8f);
chassisFrame,
explosionCenter,
Mathf.Sqrt(this.HandlingData.Mass) * VehicleManager.Instance.explosionChassisForceMultiplier,
explosionRadius,
this.HandlingData.Mass * 0.8f);
} }
// inflict damage to nearby objects // inflict damage to nearby objects
Damageable.InflictDamageToObjectsInArea( Damageable.InflictDamageToObjectsInArea(
explosionCenter, this.transform.position,
VehicleManager.Instance.explosionDamageRadius, VehicleManager.Instance.explosionDamageRadius,
Mathf.Pow(this.HandlingData.Mass, VehicleManager.Instance.explosionMassToDamageExponent), Mathf.Pow(this.HandlingData.Mass, VehicleManager.Instance.explosionMassToDamageExponent),
VehicleManager.Instance.explosionDamageOverDistanceCurve, VehicleManager.Instance.explosionDamageOverDistanceCurve,
DamageType.Explosion); DamageType.Explosion);
// create explosion effect // create explosion - this includes effects, physics force, sound
GameObject explosionGo = Object.Instantiate(VehicleManager.Instance.explosionPrefab, this.transform.position, this.transform.rotation); GameObject explosionGo = Object.Instantiate(VehicleManager.Instance.explosionPrefab, this.transform.position, this.transform.rotation);
@ -208,8 +199,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
} }
void DetachFrameDuringExplosion( void DetachFrameDuringExplosion(Frame frame, float mass)
Frame frame, Vector3 explosionCenter, float explosionForce, float explosionRadius, float mass)
{ {
var meshFilter = frame.GetComponentInChildren<MeshFilter>(); var meshFilter = frame.GetComponentInChildren<MeshFilter>();
if (null == meshFilter) if (null == meshFilter)
@ -228,8 +218,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles
rigidBody.mass = mass; rigidBody.mass = mass;
rigidBody.drag = 0.05f; rigidBody.drag = 0.05f;
rigidBody.maxDepenetrationVelocity = VehicleManager.Instance.explosionLeftoverPartsMaxDepenetrationVelocity; rigidBody.maxDepenetrationVelocity = VehicleManager.Instance.explosionLeftoverPartsMaxDepenetrationVelocity;
//rigidBody.AddExplosionForce(explosionForce, explosionCenter, explosionRadius);
Object.Destroy(meshFilter.gameObject, VehicleManager.Instance.explosionLeftoverPartsLifetime * Random.Range(0.8f, 1.2f)); Object.Destroy(meshFilter.gameObject, VehicleManager.Instance.explosionLeftoverPartsLifetime * Random.Range(0.8f, 1.2f));
} }

View file

@ -86,7 +86,7 @@ namespace SanAndreasUnity.Utilities
float closestPointDistance = float.MaxValue; float closestPointDistance = float.MaxValue;
foreach (var collider in pair.Value) foreach (var collider in colliders)
{ {
Vector3 closestPointOnCollider = collider.ClosestPointOrBoundsCenter(center); Vector3 closestPointOnCollider = collider.ClosestPointOrBoundsCenter(center);
float distanceToPointOnCollider = Vector3.Distance(center, closestPointOnCollider); float distanceToPointOnCollider = Vector3.Distance(center, closestPointOnCollider);