| | 1 | | using Cinemachine; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.Camera |
| | 5 | | { |
| | 6 | | public class CameraDampOnGroundType |
| | 7 | | { |
| | 8 | | [System.Serializable] |
| | 9 | | public class Settings |
| | 10 | | { |
| 0 | 11 | | public bool enabled = true; |
| | 12 | | public float dampingOnAir; |
| | 13 | | public float dampingOnGround; |
| | 14 | | public float dampingOnMovingPlatform; |
| | 15 | |
|
| | 16 | | [Tooltip("Min raycast ground distance to be considered airborne")] |
| | 17 | | public float groundCheckThreshold; |
| | 18 | | } |
| | 19 | |
|
| | 20 | | private FollowWithDamping followWithDamping; |
| | 21 | | public Settings settings; |
| | 22 | |
|
| 125 | 23 | | public CameraDampOnGroundType (Settings settings, FollowWithDamping followWithDamping) |
| | 24 | | { |
| 125 | 25 | | this.settings = settings; |
| 125 | 26 | | this.followWithDamping = followWithDamping; |
| 125 | 27 | | } |
| | 28 | |
|
| | 29 | | public void Update(bool hitGround, RaycastHit hitInfo) |
| | 30 | | { |
| 7 | 31 | | if ( !settings.enabled ) |
| 7 | 32 | | return; |
| | 33 | |
|
| 0 | 34 | | bool isOnMovingPlatform = DCLCharacterController.i.isOnMovingPlatform; |
| | 35 | |
|
| 0 | 36 | | if ( hitGround ) |
| | 37 | | { |
| 0 | 38 | | if ( hitInfo.distance < settings.groundCheckThreshold ) |
| 0 | 39 | | followWithDamping.damping.y = isOnMovingPlatform ? settings.dampingOnMovingPlatform : settings.dampi |
| | 40 | | else |
| 0 | 41 | | followWithDamping.damping.y = settings.dampingOnAir; |
| | 42 | | } |
| 0 | 43 | | } |
| | 44 | | } |
| | 45 | | } |