KAS.KASModuleWinch.LimitFreeFlyDistance C# (CSharp) Method

LimitFreeFlyDistance() private method

A coroutine to restore performance collision check mode.
Given the maximum length of the cable this coroutine estimates how long will it take for a harpoon to hit anything, and this time is used as a timeout. When a target is hit the collision check mode get reset in the harpoon's code right at the impact. If harpoon hit nothing then this coroutine will disable the mode by timeout.
private LimitFreeFlyDistance ( Rigidbody rb, float maxLength ) : IEnumerator
rb UnityEngine.Rigidbody
maxLength float
return IEnumerator
        IEnumerator LimitFreeFlyDistance(Rigidbody rb, float maxLength)
        {
            StopCoroutine("LimitFreeFlyDistance");  // In case of one is running.

            // Give one physics update frame for the eject force to apply.
            yield return new WaitForFixedUpdate();

            // Figure out how much time it will take for harpoon to fly at the maximum distance.
            var maxTimeToFly = cableJointLength / rb.velocity.magnitude;
            KAS_Shared.DebugLog(
            "Projectile {0} has been ejected at speed {1}. Max cable length {2} will be exahusted"
            + " in {3} seconds.",
            rb, rb.velocity.magnitude, maxLenght, maxTimeToFly);
            yield return new WaitForSeconds(maxTimeToFly + 0.5f);  // Add a delta just in case.

            // Restore performance mode if harpoon hasn't hit anyting.
            if (rb.collisionDetectionMode != CollisionDetectionMode.Discrete) {
              rb.collisionDetectionMode = CollisionDetectionMode.Discrete;
              KAS_Shared.DebugLog(
              "Projectile {0} hasn't hit anything. Reset collision check mode to Discrete", rb);
            }
        }