Hi there, I am trying to clamp my camera angle and have looked at various topics here but can’t work out why it jitters while rotating on specific angles. I have some ideas, but even so I’m not sure how to fix it.
For example - If my camera is directly behind my character and I raise it up over his head, it clamps perfectly, same with under the character, but if it’s been rotated horizontally around the character the camera jitters horribly when I try to move it vertically.
This is the code I’m using:
void FreeCamera(float mh, float mv)
{
float rotationAmount;
float rotationHAmount;
if(((mh > deadZone || mh < -deadZone)) || (mh > deadZone || mh < -deadZone))
{
rotationHAmount = mh * hRotateSpeed * Time.deltaTime;
camera.transform.RotateAround(target.transform.position, Vector3.up, rotationHAmount);
}
if(((mv > deadZone || mv < -deadZone)) || (mv > deadZone || mv < -deadZone))
{
rotationAmount = mv * -1.0f * vRotateSpeed * Time.deltaTime;
Vector3 currentVector = transform.position - target.transform.position;
float angleBetween = Vector3.Angle(initialVector, currentVector) * (Vector3.Cross(initialVector, currentVector).x > 0 ? 1 : -1);
float newAngle = Mathf.Clamp(angleBetween + rotationAmount, -maxAngle, maxAngle);
rotationAmount = newAngle - angleBetween;
camera.transform.RotateAround(target.transform.position, cam.transform.right, rotationAmount);
}
}