using Cinemachine.Utility; using UnityEngine; using UnityEngine.Serialization; namespace Cinemachine { /// /// This is a CinemachineComponent in the Aim section of the component pipeline. /// Its job is to match the orientation of the Follow target. /// [DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)] [AddComponentMenu("")] // Don't display in add component menu [SaveDuringPlay] public class CinemachineSameAsFollowTarget : CinemachineComponentBase { /// /// How much time it takes for the aim to catch up to the target's rotation /// [Tooltip("How much time it takes for the aim to catch up to the target's rotation")] [FormerlySerializedAs("m_AngularDamping")] public float m_Damping = 0; Quaternion m_PreviousReferenceOrientation = Quaternion.identity; /// True if component is enabled and has a Follow target defined public override bool IsValid { get { return enabled && FollowTarget != null; } } /// Get the Cinemachine Pipeline stage that this component implements. /// Always returns the Aim stage public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } } /// /// Report maximum damping time needed for this component. /// /// Highest damping setting in this component public override float GetMaxDampTime() { return m_Damping; } /// Orients the camera to match the Follow target's orientation /// The current camera state /// Not used. public override void MutateCameraState(ref CameraState curState, float deltaTime) { if (!IsValid) return; Quaternion dampedOrientation = FollowTargetRotation; if (deltaTime >= 0) { float t = VirtualCamera.DetachedFollowTargetDamp(1, m_Damping, deltaTime); dampedOrientation = Quaternion.Slerp( m_PreviousReferenceOrientation, FollowTargetRotation, t); } m_PreviousReferenceOrientation = dampedOrientation; curState.RawOrientation = dampedOrientation; curState.ReferenceUp = dampedOrientation * Vector3.up; } } }