Question by
Aphid98 · Oct 01, 2017 at 06:40 PM ·
camera-lookjitteringthird-person-camera
Third Person Camera Jittering
I'm try to write a third person script for a project I'm working on, and it works the way I want it to but the issue is that it keeps jittering. I have tried changing the LateUpdate to both Fixed and normal update and none of it seems to work... Any ideas?
here is the code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseAimCamera : MonoBehaviour {
public GameObject target;
public float rotateSpeed = 5;
public float smooth = 3f;
public Vector3 offset;
void LateUpdate() {
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
target.transform.Rotate(0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
transform.position = Vector3.Lerp(transform.position, target.transform.position - (rotation * offset), smooth * Time.deltaTime);
transform.LookAt(target.transform.position + new Vector3(0f, 1f));
}
}
Comment
Your answer