I’m trying to create a simple third person follow camera using Cinemachine, and while I’m very happy with how simple it was to setup, I’m having some trouble getting it to move smoothly around the player. I’m using a gamepad for input and as I move the joystick in any direction and with any intensity, the camera will move in a very jerky way (link to video below). I know it’s not a frame rate issue, so I assume that there is either a cinemachine setting I’m not aware of that can smooth this out, or there is something I could do in the camera control script to make it move more smoothly. Just looking for some feedback from folks who have worked with this before.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine.InputSystem;
using System.Linq.Expressions;
[RequireComponent(typeof(CinemachineFreeLook))]
public class FreeLookAddOn : MonoBehaviour
{
[Range(0f, 100f)] public float LookSpeed = 50f;
public bool InvertY = false;
private CinemachineFreeLook _freeLookComponent;
PlayerControls controls;
Vector2 rotate;
public void Awake()
{
controls = new PlayerControls();
_freeLookComponent = GetComponent<CinemachineFreeLook>();
controls.Gameplay.Rotate.performed += ctx1 => rotate = ctx1.ReadValue<Vector2>();
controls.Gameplay.Rotate.canceled += ctx1 => rotate = Vector2.zero;
}
private void Update()
{
Vector2 lookMovement = new Vector2(rotate.x,rotate.y).normalized * Time.deltaTime;
lookMovement.y = InvertY ? -lookMovement.y : lookMovement.y;
lookMovement.x = lookMovement.x * 180f;
_freeLookComponent.m_XAxis.Value += lookMovement.x * LookSpeed * Time.deltaTime;
_freeLookComponent.m_YAxis.Value += lookMovement.y * LookSpeed * Time.deltaTime;
}
private void OnEnable()
{
controls.Gameplay.Enable();
}
private void OnDisable()
{
controls.Gameplay.Disable();
}
}