private IEnumerator CorrectCamera() { _isCameraCorrecting = true; var delta = transform.position - Camera.position; delta.y = 0f; if (!ScreenFader) { CameraRig.transform.position += delta; _isCameraCorrecting = false; yield break; } ScreenFader.Fade(1, HeadCollisionFadeSpeed); while (ScreenFader.CurrentFade < .9) { yield return(null); } delta = transform.position - Camera.position; delta.y = 0f; CameraRig.transform.position += delta; ScreenFader.Fade(0, HeadCollisionFadeSpeed); while (ScreenFader.CurrentFade > .1) { yield return(null); } _isCameraCorrecting = false; }
void FixedUpdate() { DistanceToMostClosePoint = 1; IsColliding = false; var hits = Physics.OverlapSphereNonAlloc(transform.position, OuterRadius, _hits, LayerMask, QueryTriggerInteraction.Ignore); if (hits > 0) { //DistanceToMostClosePoint = 0f; if (Physics.OverlapSphereNonAlloc(transform.position, EyeRadius, _hitsDummy, LayerMask, QueryTriggerInteraction.Ignore) > 0) { IsColliding = true; DistanceToMostClosePoint = 0; } else { for (var i = 0; i < hits; i++) { var centerOfHit = _hits[i].bounds.center; var direction = centerOfHit - transform.position; if (Physics.SphereCast(transform.position, RadiusOfSphereCast, direction, out RaycastHit hit, Vector3.Distance(transform.position, centerOfHit), LayerMask)) { if (hit.distance < DistanceToMostClosePoint) { DistanceToMostClosePoint = hit.distance; } } } } } var fade = 1 - DistanceToMostClosePoint; if (ScreenFade) { if (fade > .001f) { ScreenFade.Fade(fade, FadeSpeed); } else { ScreenFade.UpdateFade(0f); } } }