Hello!
I have this problem with my camera. Whenever the camera is looking up and the character walks up a slope, the camera jitters.
I’m pretty sure I narrowed the problem down to the collider.
Heres the code for the Collider:
public float minDistance = 1.0f;
public float maxDistance = 5.0f;
public float smooth;
public float distance;
Vector3 dollyDir;
public GameObject cameraBase;
public FPCamController fpCamController;
// Use this for initialization
void Start() {
distance = transform.localPosition.magnitude;
}
// Update is called once per frame
void Update() {
dollyDir = transform.localPosition.normalized;
Vector3 desiredCameraPos = transform.parent.TransformPoint(dollyDir * maxDistance);
RaycastHit hit;
if (Physics.Linecast(cameraBase.transform.position, desiredCameraPos, out hit)) {
distance = Mathf.Clamp(hit.distance * 0.87f, minDistance, maxDistance);
} else {
distance = maxDistance;
}
transform.localPosition = Vector3.Lerp(transform.localPosition, dollyDir * (distance - .25f), Time.deltaTime * smooth);
print(transform.localPosition);
}
Here’s a video of the problem
P.S. If some of the code is not the best, forgive me I’m new