I have this script for a third person camera:
using UnityEngine;
using System.Collections;
public class ThirdPersonCamera : MonoBehaviour {
public GameObject target;
public float rotateSpeed = 5;
Vector3 offset;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
target.transform.Rotate(0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt (target.transform);
}
}
it works fine except that there is no vertical camera rotation so I can’t look up or down, what I’m after is a camera similar to the one in the Jedi Knight games.
how do i get the camera to look up or down?
void LateUpdate()
{
float horizontal = Input.GetAxis(“Mouse X”) * rotateSpeed;
float vertical = Input.GetAxis(“Mouse Y”) * rotateSpeed;
target.transform.Rotate(vertical, horizontal, 0);
float desiredAngle_X = target.transform.eulerAngles.x;
float desiredAngle_Y = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(desiredAngle_X, desiredAngle_Y, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt (target.transform);
}