- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
A_knot · Mar 08, 2015 at 01:32 AM ·
camera-movementcamera rotatecamera-look
follow camera that rotates when i change direction
Hi everyone !
I need a third person camera that smoothly rotates around the player object when i change the direction the player object is going (rolling) in with the arrow keys. The player object in this case is a rolling ball where i've added forces to the axis. I found this script and tried it:
using UnityEngine; using System.Collections;
public class FollowCam : MonoBehaviour { public GameObject target; public float damping = 1; Vector3 offset;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate() {
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.transform.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
but the camera just keep rotating between two axis continuesly. Is there a way to clamp the camera to an angle or something ? can't get my head around this one.
if anyone have any suggestions, please share :)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613185232im_/https://answers.unity.com/themes/thub/images/avi.jpg)