Hello. Im using a C# script from a tutorial that allows your Camera to rotate around a game object. It’s working well, except it always points to my character’s feet. Its not locked to the character’s pivot because when I move the character’s position my camera continues to aim at the ground. Can anyone tell me how to aim the Camera to my character’s head?
here is the script:
using UnityEngine;
using System.Collections;
public class MouseAimCamera : 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;
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);
}
}