//------------------------------------------------------------------------------------------------ // Edy's Vehicle Physics // (c) Angel Garcia "Edy" - Oviedo, Spain // http://www.edy.es //------------------------------------------------------------------------------------------------ using UnityEngine; namespace EVP { // Data stored per wheel for tire effects public class TireFxData { // Tire marks public TireMarksRenderer lastRenderer; public int lastMarksIndex = -1; public float marksDelta = 0.0f; // Tire particles public TireParticleEmitter lastEmitter; public float lastParticleTime = -1.0f; public float slipTime = 0.0f; } [RequireComponent(typeof(VehicleController))] public class VehicleTireEffects : MonoBehaviour { public float tireWidth = 0.2f; public float minSlip = 1.0f; public float maxSlip = 5.0f; [Header("Tire marks")] [Range(0,2)] public float intensity = 1.0f; public float updateInterval = 0.02f; [Header("Smoke")] public float minIntensityTime = 0.5f; public float maxIntensityTime = 6.0f; public float limitIntensityTime = 10.0f; VehicleController m_vehicle; TireFxData[] m_fxData = new TireFxData[0]; void OnEnable () { m_vehicle = GetComponent(); m_vehicle.computeExtendedTireData = true; } void Update () { if (m_vehicle.paused) return; if (m_vehicle.wheelData.Length != m_fxData.Length) InitializeTireFxData(); for (int i=0, c=m_fxData.Length; i 0.0f && particleEmitter.mode == TireParticleEmitter.Mode.PressureAndSkid) fxData.slipTime += Time.deltaTime * skidRatio * pressureRatio; else fxData.slipTime -= Time.deltaTime; fxData.slipTime = Mathf.Clamp(fxData.slipTime, 0.0f, limitIntensityTime); float slipTimeRatio = Mathf.InverseLerp(minIntensityTime, maxIntensityTime, fxData.slipTime); fxData.lastParticleTime = particleEmitter.EmitParticle( position + positionRandom, wheelData.velocity, wheelData.tireSlip.y * wheelData.transform.forward, pressureRatio, skidRatio * slipTimeRatio, fxData.lastParticleTime ); } else { // No particles set up for this material. Assume is not a "heating material" // and "cold down" the tire surface. fxData.slipTime -= Time.deltaTime; if (fxData.slipTime < 0.0f) fxData.slipTime = 0.0f; } } } }