Third Person Camera locked on to player.

hi, very new to unity but i was wondering if i could get a hand with the coding.

i’m making a script for a third person camera and it is following the player fine, however when i rotate the player the camera stays static and eventually the player faces the camera, i want the camera to rotate with the player.
i’m sure this is simple but i just need a helping hand to get started, here is my code:

using UnityEngine;
public class Camera_Follow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
void LateUpdate ()
{
Vector3 desiredPosition = target.position + offset;
Vector3 smoothedPosition = Vector3.Lerp (transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
}
}

i am aware that i could make the player a parent but i want the camera to have a slight delay between the player rotating and the camera.
thanks in advance!

If you’re going to handle it all in this script, you’re going to need to track the target’s rotation from the previous frame, compare it to the current rotation to get yourself a delta, and then reposition and rotate the camera to match. To do it with a delay you’re probably going to want to create a queue where you’re adding these deltas with a timestamp to apply them in the future (at least that is probably how I’d do this kind of thing). Could be a bit tricky to get to feel right, since you might want to apply the rotations at a different speed than the target turns.

1 Like