- Home /
Question by
KitsuneWarriorr · Dec 10, 2014 at 10:34 AM ·
c#camera-movement
Can't find fix for buggy camera
I'm working on a big project and we're almost done, but when the character goes far to the left or the right the camera completely freaks out and I don't know how to fix it. The camera is supposed to follow the character smoothly but when far enough to the edges it it jitters a lot.
using UnityEngine;
using System.Collections;
public class CameraControllerComponent : MonoBehaviour {
[SerializeField]
private PlayerComponent player;
[SerializeField]
private Transform gravityTracker;
[SerializeField]
private float lerpValue = 0.1f;
[SerializeField]
private float velocityLead = 0.1f;
[SerializeField]
private float slerpValue = 0.1f;
[Range(0.1f, 2f)]
[SerializeField]
private float tubeNormalTracking = 1f;
private void Update() {
transform.position = Vector3.Lerp(transform.position, player.transform.position + player.rigidbody.velocity * velocityLead, lerpValue);
//transform.position = player.transform.position;
if (player.CurrentTube == null) {
gravityTracker.rotation = Quaternion.Slerp(gravityTracker.rotation, Quaternion.LookRotation(Vector3.forward, -Physics.gravity), slerpValue);
} else {
gravityTracker.rotation = Quaternion.Slerp(gravityTracker.rotation, Quaternion.LookRotation(Vector3.forward, player.CurrentTube.GetNormalFromTubePosition(player.PositionOnTube / (1f/tubeNormalTracking))), slerpValue);
}
}
}
Any and all help would be very appreciated
Comment