I’m trying to get a simple 3rd person camera to work. All I want it to do for now is follow my player (a non rigidbody capsule) with the ability to rotate the camera in any direction depending on the mouse movements. Most tutorials I’ve gone through are advanced cameras which I don’t want to dive into yet.
Here’s my current attempt:
using UnityEngine;
using System.Collections;
public class CameraController : 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(vertical, 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);
}
}
The mouse movements are rotating the player instead of the camera though.