public bool Calc(Vector3 cur, Vector3 birdDir, Collider cld, out Force force) { var pointOnBounds = MathTools.CalcPointOnBounds(cld, cur); var revDir = cur - pointOnBounds; var dist = revDir.magnitude; if (dist <= MathTools.epsilon) { //Let's setup the direction to outside of colider revDir = (pointOnBounds - cld.transform.position).normalized; //and distance to N percent of OptDistance dist = 0.1f * optDistance; } else { revDir /= dist; } //Force depends on direction of bird: no need to turn a bird if it is flying in opposite direction force.dir = revDir * (CalcImpl(dist) * MathTools.AngleToFactor(revDir, birdDir)); force.pos = pointOnBounds; return(true); }