I’m kind of new to Unity, and I’m trying to make a 3rd person and 1st person camera. The cameras were rotating fine before, but right now for some reason they are rotating too fast sometimes even though I didn’t change anything in the scripts. Here is the script and the components:
using UnityEngine;
using Cinemachine;
public class CameraController : MonoBehaviour
{
[SerializeField] HumanoidLandInput _input;
[SerializeField] float _cameraZoomModifier = 32.0f;
float _minCameraZoomDistance = 1.125f;
float _maxCameraZoomDistance = 3.0f;
CinemachineVirtualCamera _activeCamera;
int _activeCameraPriorityModifer = 31337;
public Camera MainCamera;
public CinemachineVirtualCamera cinemachine1stPerson;
public CinemachineVirtualCamera cinemachine3rdPerson;
CinemachineFramingTransposer _cinemachineFramingTransposer3rdPerson;
private void Awake()
{
_cinemachineFramingTransposer3rdPerson = cinemachine3rdPerson.GetCinemachineComponent<CinemachineFramingTransposer>();
}
private void Start()
{
ChangeCamera(); // First time through, lets set the default camera.
}
private void Update()
{
if (!(_input.ZoomCameraInput == 0.0f)) { ZoomCamera(); }
if (_input.ChangeCameraWasPressedThisFrame) { ChangeCamera(); }
}
private void ZoomCamera()
{
if (_activeCamera == cinemachine3rdPerson)
{
_cinemachineFramingTransposer3rdPerson.m_CameraDistance = Mathf.Clamp(_cinemachineFramingTransposer3rdPerson.m_CameraDistance +
(_input.InvertScroll ? _input.ZoomCameraInput : -_input.ZoomCameraInput) / _cameraZoomModifier,
_minCameraZoomDistance,
_maxCameraZoomDistance);
}
}
private void ChangeCamera()
{
if (cinemachine3rdPerson == _activeCamera)
{
SetCameraPriorities(cinemachine3rdPerson, cinemachine1stPerson);
MainCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("Player (Self)"));
}
else if (cinemachine1stPerson == _activeCamera)
{
SetCameraPriorities(cinemachine1stPerson, cinemachine3rdPerson);
_activeCamera = cinemachine3rdPerson;
MainCamera.cullingMask |= 1 << LayerMask.NameToLayer("Player (Self)");
}
else // for first time through or if there's an error
{
cinemachine3rdPerson.Priority += _activeCameraPriorityModifer;
_activeCamera = cinemachine3rdPerson;
}
}
private void SetCameraPriorities(CinemachineVirtualCamera CurrentCameraMode, CinemachineVirtualCamera NewCameraMode)
{
CurrentCameraMode.Priority -= _activeCameraPriorityModifer;
NewCameraMode.Priority += _activeCameraPriorityModifer;
_activeCamera = NewCameraMode;
}
}
ihdwpc