using UnityEngine; using System.Collections; public class FollowCamRotation : MonoBehaviour { public GameObject cam; public float speed = 0.9f; public float xPos = 0; public float zPos = 1.5f; public float yPos = 1.0f; float mag; Vector3 vPointing; void Start () { vPointing = xPos * cam.transform.right + yPos * Vector3.up + zPos * cam.transform.forward; mag = Mathf.Sqrt(xPos * xPos + zPos * zPos); } void Update () { Vector3 vPoint = xPos *cam.transform.right + zPos *cam.transform.forward; vPoint.y = 0.0f; vPoint.Normalize(); vPoint *= mag; vPointing = Vector3.Lerp(vPointing,vPoint, speed * Time.deltaTime); vPointing.Normalize(); vPoint *= mag; vPointing.y = yPos; transform.position = cam.transform.position + vPointing; Quaternion q = Quaternion.LookRotation(cam.transform.position - transform.position); transform.forward = cam.transform.forward; } }