I am trying to figure out how to clamp the Y axis for my 3rd person orbit camera. I never figured out how to clamp rotations properly, but here is my code in C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public float maxY, minY;
public Transform target;
public Vector3 offset;
public float turnSpeed = 4;
void Start(){
offset = new Vector3 (target.position.x, target.position.y + 8, target.position.z - 7);
}
void LateUpdate(){
offset = Quaternion.AngleAxis (Input.GetAxis ("RHorizontal") * turnSpeed, Vector3.up) * offset;
offset = Quaternion.AngleAxis (Input.GetAxis ("RVertical") * turnSpeed, Vector3.right) * offset;
offset.y = Mathf.Clamp (offset.y, minY, maxY);
transform.position = target.position + offset;
transform.LookAt (target.position);
}
}
Thanks to anyone in advanced that helps me out