< Summary

Class:DCL.Camera.CameraDampOnSprint
Assembly:Camera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/CameraDampOnSprint.cs
Covered lines:11
Uncovered lines:12
Coverable lines:23
Total lines:66
Line coverage:47.8% (11 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Settings()0%110100%
CameraDampOnSprint(...)0%110100%
Update()0%20.745014.29%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/CameraDampOnSprint.cs

#LineLine coverage
 1using Cinemachine;
 2using Cinemachine.Utility;
 3using UnityEngine;
 4
 5
 6namespace DCL.Camera
 7{
 8    /// <summary>
 9    /// This class ensures that upon sprinting forward, the camera slowly backs down.
 10    /// Camera will slowly recover when not sprinting or moving in any other direction that's not forward.
 11    /// </summary>
 12    public class CameraDampOnSprint
 13    {
 14        [System.Serializable]
 15        public class Settings
 16        {
 59817            public bool enabled = true;
 18            public float distanceMin;
 19            public float distanceMax;
 20            public float fovMax;
 21            public float fovMin;
 59822            public float inDampingDelay = 5;
 59823            public float inDampingTime = 5f;
 59824            public float outDampingTime = 2.5f;
 25        }
 26
 27        private CinemachineFreeLook sourceFreeLook;
 28        private InputAction_Measurable characterYAxis;
 29        public Settings settings;
 30
 31        private float currentDampingDelay = 0;
 32
 59733        public CameraDampOnSprint (Settings settings, CinemachineFreeLook freeLook, InputAction_Measurable characterYAxi
 34        {
 59735            this.settings = settings;
 59736            this.sourceFreeLook = freeLook;
 59737            this.characterYAxis = characterYAxis;
 59738        }
 39
 40        public void Update()
 41        {
 219842            if ( !settings.enabled )
 219843                return;
 44
 045            var orbit = sourceFreeLook.m_Orbits[1];
 046            if (characterYAxis.GetValue() > 0 && !DCLCharacterController.i.isWalking)
 47            {
 048                currentDampingDelay += Time.deltaTime;
 49
 050                if ( currentDampingDelay > settings.inDampingDelay )
 51                {
 052                    orbit.m_Radius += Damper.Damp(settings.distanceMax - orbit.m_Radius, settings.inDampingTime, Time.de
 053                    sourceFreeLook.m_Lens.FieldOfView += Damper.Damp(settings.fovMax - sourceFreeLook.m_Lens.FieldOfView
 54                }
 055            }
 56            else
 57            {
 058                currentDampingDelay = 0;
 059                orbit.m_Radius += Damper.Damp(settings.distanceMin - orbit.m_Radius, settings.outDampingTime, Time.delta
 060                sourceFreeLook.m_Lens.FieldOfView += Damper.Damp(settings.fovMin - sourceFreeLook.m_Lens.FieldOfView, se
 61            }
 62
 063            sourceFreeLook.m_Orbits[1] = orbit;
 064        }
 65    }
 66}