| | 1 | | using Cinemachine; |
| | 2 | | using Cinemachine.Utility; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | |
|
| | 6 | | namespace 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 | | { |
| 598 | 17 | | public bool enabled = true; |
| | 18 | | public float distanceMin; |
| | 19 | | public float distanceMax; |
| | 20 | | public float fovMax; |
| | 21 | | public float fovMin; |
| 598 | 22 | | public float inDampingDelay = 5; |
| 598 | 23 | | public float inDampingTime = 5f; |
| 598 | 24 | | 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 | |
|
| 597 | 33 | | public CameraDampOnSprint (Settings settings, CinemachineFreeLook freeLook, InputAction_Measurable characterYAxi |
| | 34 | | { |
| 597 | 35 | | this.settings = settings; |
| 597 | 36 | | this.sourceFreeLook = freeLook; |
| 597 | 37 | | this.characterYAxis = characterYAxis; |
| 597 | 38 | | } |
| | 39 | |
|
| | 40 | | public void Update() |
| | 41 | | { |
| 2198 | 42 | | if ( !settings.enabled ) |
| 2198 | 43 | | return; |
| | 44 | |
|
| 0 | 45 | | var orbit = sourceFreeLook.m_Orbits[1]; |
| 0 | 46 | | if (characterYAxis.GetValue() > 0 && !DCLCharacterController.i.isWalking) |
| | 47 | | { |
| 0 | 48 | | currentDampingDelay += Time.deltaTime; |
| | 49 | |
|
| 0 | 50 | | if ( currentDampingDelay > settings.inDampingDelay ) |
| | 51 | | { |
| 0 | 52 | | orbit.m_Radius += Damper.Damp(settings.distanceMax - orbit.m_Radius, settings.inDampingTime, Time.de |
| 0 | 53 | | sourceFreeLook.m_Lens.FieldOfView += Damper.Damp(settings.fovMax - sourceFreeLook.m_Lens.FieldOfView |
| | 54 | | } |
| 0 | 55 | | } |
| | 56 | | else |
| | 57 | | { |
| 0 | 58 | | currentDampingDelay = 0; |
| 0 | 59 | | orbit.m_Radius += Damper.Damp(settings.distanceMin - orbit.m_Radius, settings.outDampingTime, Time.delta |
| 0 | 60 | | sourceFreeLook.m_Lens.FieldOfView += Damper.Damp(settings.fovMin - sourceFreeLook.m_Lens.FieldOfView, se |
| | 61 | | } |
| | 62 | |
|
| 0 | 63 | | sourceFreeLook.m_Orbits[1] = orbit; |
| 0 | 64 | | } |
| | 65 | | } |
| | 66 | | } |