Locking Camera's rotation on a rolling character
I'm trying to create a basic 3rd person camera, that follows the player and rotates to always stay behind it. The script kind of works but the character I'm using is a capsual shape, meaning their movement is done via physically rolling the object, I think this is causing the camera to flip around everytime the player does a revolution. Here's the camera script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMoter : 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, damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
Here's a link to a video showing what the problem is, any help would be appreciated, many thanks.
Your answer
Follow this Question
Related Questions
,Third Person Movement Script Help 0 Answers
Help With Camera rotation on X and Y Axis (Target Focused) 1 Answer
viewing on the Mouse Y axis not working. 0 Answers
How to have your player controls change while your camera rotates? 0 Answers
Using DampSmooth in EulerAngle is affecting the Position.Z value of the gameObject. 0 Answers