void ComputeWind() { Vector3 newWind; if (overrideWind != Vector3.zero) { newWind = overrideWind; } else // Procedural wind { for (int i = 0; i < 4; i++) { randTimes[i] += Time.deltaTime * randSpeeds[i] * turbulenceSpeed; } Quaternion windDir = windOrientation; float x = -1f + Mathf.PerlinNoise(randTimes[0], 256f + randTimes[1]) * 2f; float y = -1f + Mathf.PerlinNoise(-randTimes[1], 55f + randTimes[2]) * 2f; float z = -1f + Mathf.PerlinNoise(-randTimes[3], 55f + randTimes[0]) * 2f; windDir *= Quaternion.Euler(new Vector3(0, y, 0) * changesPower); windDir = Quaternion.Euler(x * (changesPower / 6f), windDir.eulerAngles.y, z * (changesPower / 6f)); smoothWindOrient = FEngineering.SmoothDampRotation(smoothWindOrient, windDir, ref smoothWindOrientHelper, 1f - rapidness, Time.deltaTime); transform.rotation = smoothWindOrient; newWind = smoothWindOrient * Vector3.forward; } // Additional turbulence smoothAddTurbulence = Vector3.SmoothDamp(smoothAddTurbulence, GetAddTurbulence() * additionalTurbulence, ref addTurbHelper, 0.05f, Mathf.Infinity, Time.deltaTime); // Smooth out smoothWind = Vector3.SmoothDamp(smoothWind, newWind, ref windVeloHelper, 0.1f, Mathf.Infinity, Time.deltaTime); for (int i = 7; i < 10; i++) { randTimes[i] += Time.deltaTime * randSpeeds[i] * turbulenceSpeed; } float turbulencedPower = power * 0.015f; turbulencedPower *= 0.5f + Mathf.PerlinNoise(randTimes[7] * 2f, 25 + randTimes[8] * 0.5f); finalAddTurbulence = smoothAddTurbulence * turbulencedPower; targetWind = smoothWind * turbulencedPower; }
/// <summary> Smoothing rotation for _tc_bone with smooth damp method changing _tc_smoothRot variable in iteration towards _tc_targetRot </summary> Quaternion TailCalculations_SmoothRotationSmoothDamp(Quaternion from, Quaternion to, ref Quaternion velo, float speed) { return(FEngineering.SmoothDampRotation(from, to, ref velo, Mathf.LerpUnclamped(0.25f, 0.0001f, Mathf.Sqrt(Mathf.Sqrt(speed))), rateDelta)); }