From 2e0108d662d55dd8d5d0cac76355ef3796c7869d Mon Sep 17 00:00:00 2001 From: in0finite Date: Wed, 1 Jul 2020 19:25:59 +0200 Subject: [PATCH] cleanup code --- .../Behaviours/Vehicles/VehicleManager.cs | 2 -- .../Behaviours/Vehicles/Vehicle_Damage.cs | 27 ++++++------------- Assets/Scripts/Utilities/Damageable.cs | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Assets/Scripts/Behaviours/Vehicles/VehicleManager.cs b/Assets/Scripts/Behaviours/Vehicles/VehicleManager.cs index f8823120..6ce2ebe2 100644 --- a/Assets/Scripts/Behaviours/Vehicles/VehicleManager.cs +++ b/Assets/Scripts/Behaviours/Vehicles/VehicleManager.cs @@ -23,8 +23,6 @@ namespace SanAndreasUnity.Behaviours.Vehicles [Range(0.1f, 3f)] public float massToHealthExponent = 1f; - 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; diff --git a/Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs b/Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs index 0f8c0f90..42741d6c 100644 --- a/Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs +++ b/Assets/Scripts/Behaviours/Vehicles/Vehicle_Damage.cs @@ -146,13 +146,10 @@ namespace SanAndreasUnity.Behaviours.Vehicles 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_" }; - Vector3 explosionCenter = this.transform.position; - float explosionForce = Mathf.Sqrt(this.HandlingData.Mass) * VehicleManager.Instance.explosionForceMultiplier; - float explosionRadius = 10f; - + foreach (var frame in _frames) { if (!frame.gameObject.activeInHierarchy) @@ -161,8 +158,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles if (!startingNames.Any(n => frame.gameObject.name.StartsWith(n))) continue; - DetachFrameDuringExplosion( - frame, explosionCenter, explosionForce, explosionRadius, VehicleManager.Instance.explosionLeftoverPartsMass); + DetachFrameDuringExplosion(frame, VehicleManager.Instance.explosionLeftoverPartsMass); } // chassis need to be handled after all other objects are detached, because chassis can sometimes @@ -176,24 +172,19 @@ namespace SanAndreasUnity.Behaviours.Vehicles } else { - DetachFrameDuringExplosion( - chassisFrame, - explosionCenter, - Mathf.Sqrt(this.HandlingData.Mass) * VehicleManager.Instance.explosionChassisForceMultiplier, - explosionRadius, - this.HandlingData.Mass * 0.8f); + DetachFrameDuringExplosion(chassisFrame, this.HandlingData.Mass * 0.8f); } // inflict damage to nearby objects Damageable.InflictDamageToObjectsInArea( - explosionCenter, + this.transform.position, VehicleManager.Instance.explosionDamageRadius, Mathf.Pow(this.HandlingData.Mass, VehicleManager.Instance.explosionMassToDamageExponent), VehicleManager.Instance.explosionDamageOverDistanceCurve, 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); @@ -208,8 +199,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles } - void DetachFrameDuringExplosion( - Frame frame, Vector3 explosionCenter, float explosionForce, float explosionRadius, float mass) + void DetachFrameDuringExplosion(Frame frame, float mass) { var meshFilter = frame.GetComponentInChildren(); if (null == meshFilter) @@ -228,8 +218,7 @@ namespace SanAndreasUnity.Behaviours.Vehicles rigidBody.mass = mass; rigidBody.drag = 0.05f; rigidBody.maxDepenetrationVelocity = VehicleManager.Instance.explosionLeftoverPartsMaxDepenetrationVelocity; - //rigidBody.AddExplosionForce(explosionForce, explosionCenter, explosionRadius); - + Object.Destroy(meshFilter.gameObject, VehicleManager.Instance.explosionLeftoverPartsLifetime * Random.Range(0.8f, 1.2f)); } diff --git a/Assets/Scripts/Utilities/Damageable.cs b/Assets/Scripts/Utilities/Damageable.cs index bef4fe1b..06c734bd 100644 --- a/Assets/Scripts/Utilities/Damageable.cs +++ b/Assets/Scripts/Utilities/Damageable.cs @@ -86,7 +86,7 @@ namespace SanAndreasUnity.Utilities float closestPointDistance = float.MaxValue; - foreach (var collider in pair.Value) + foreach (var collider in colliders) { Vector3 closestPointOnCollider = collider.ClosestPointOrBoundsCenter(center); float distanceToPointOnCollider = Vector3.Distance(center, closestPointOnCollider);