So I’m trying to create a basic Total War styled camera. So far I can move it…
left, right - forward, backward - rotate left and right - tilt up and down
Basically, the issue I’m having is this… Screenshot by Lightshot
I want to prevent it from turning sideways like that. How can I accomplish that? Here’s the code so far.
public float moveSpeed;
public float tiltSpeed;
public float minimumHeight;
public float rotateSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * moveSpeed * Time.deltaTime);
transform.Translate (Vector3.forward * Input.GetAxis ("Vertical") * moveSpeed * Time.deltaTime);
transform.Rotate (Vector3.right * Input.GetAxis ("Tilt") * tiltSpeed * Time.deltaTime);
transform.Rotate(Vector3.up * Input.GetAxis("Rotate") * rotateSpeed * Time.deltaTime);
if (transform.position.y < minimumHeight)
transform.Translate(0, minimumHeight - transform.position.y, 0);
}