Gif link in case it doesn’t want to work as an embed: Imgur: The magic of the Internet
I’ve been trying to get a 3rd person melee action camera together for a while now, but I keep coming across jump/jitter issues. Finally, I go with this ultra simple script and for some reason this random jump issue happens. I don’t see any reason for it whatsoever and I’m being driven insane by all the camera issues I’ve been dealing with. Hoping someone else with some fresh eyes can explain why the camera wants to randomly jump around when it moves.
Edit: So I figured out that’s it has something to do with the project, cause I created a new one, implemented the camera system, no jump issue whatsoever. Unfortunately I’m working in a project that has had quite a few cooks in the kitchen already and is a massive mess, so I have no idea what’s causing the issue but yay it’s not me being a complete dumb dumb.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public float CameraMoveSpeed = 120.0f;
public GameObject CameraFollowObj;
Vector3 FollowPos;
public float clampAngle = 80.0f;
public float inputSens = 150.0f;
public float camDistanceXToPlayer;
public float camDistanceYToPlayer;
public float camDistanceZXToPlayer;
public float mouseX;
public float mouseY;
public float finalInputX;
public float finalInputZ;
private float rotationY = 0.0f;
private float rotationX = 0.0f;
void Start()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotationY = rot.y;
rotationX = rot.x;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
float inputX = Input.GetAxis("RightStickHorizontal");
float inputZ = Input.GetAxis("RightStickVertical");
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
finalInputX = inputX + mouseX;
finalInputZ = inputZ + mouseY;
rotationY += finalInputX * inputSens * Time.deltaTime;
rotationX += finalInputZ * inputSens * Time.deltaTime;
rotationX = Mathf.Clamp(rotationX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotationX, rotationY, 0.0f);
transform.rotation = localRotation;
}
private void LateUpdate()
{
CameraUpdater();
}
void CameraUpdater()
{
Transform target = CameraFollowObj.transform;
float step = CameraMoveSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}