- Home /
 
Why is my third person camera making this arc movement?
Hi everyone, I am very new to using unity and coding with c#. I wanted to make a 3D platformer game and ive been following this tutorial: https://www.youtube.com/watch?v=h2d9Wc3Hhi0&list=PLiyfvmtjWC_V_H-VMGGAZi7n5E0gyhc37
I have finished the tutorial but a big problem i have noticed is that the camera movement when circling the player has a weird arc to it in the y axis. I read that this is a problem with using euler angles, and we should be using quaterniums instead, but from what i can see in the code, aren't we doing that already?
I really don't know how to fix this arc movement, here is the code i have for the camera controller:
 public class CameraController : MonoBehaviour
 {
     public Transform target;
     public Vector3 offset;
     public bool useOffsetValues;
     public float rotateSpeed;
     public Transform pivot;
     public float maxViewAngle;
     public float minViewAngle;
     public bool invertY;
 
     // Start is called before the first frame update
     void Start()
     {
         if(!useOffsetValues)
             offset = target.position - transform.position;
 
         pivot.transform.position = target.transform.position;
         pivot.transform.parent = null;
 
         Cursor.lockState = CursorLockMode.Locked; //Hide cursor when game starts
     }
 
     // Update is called once per frame
     void LateUpdate()
     {
         pivot.transform.position = target.transform.position;
 
         //Get x position of the mouse and rotate the target
         float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
         pivot.Rotate(0, horizontal, 0);
 
         //Get y position of the mouse and rotate the pivot
         float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
         //Give invert Y option
         if (invertY)
             pivot.Rotate(vertical, 0, 0);
         else
             pivot.Rotate(-vertical, 0, 0);
 
         //Limit up/down camera rotation
         if (pivot.rotation.eulerAngles.x > maxViewAngle && pivot.rotation.eulerAngles.x < 180.0f)
             pivot.rotation = Quaternion.Euler(maxViewAngle, pivot.eulerAngles.y, 0.0f);
         if (pivot.rotation.eulerAngles.x > 180.0f && pivot.rotation.eulerAngles.x < 360f + minViewAngle)
             pivot.rotation = Quaternion.Euler(360.0f + minViewAngle, pivot.eulerAngles.y, 0.0f);
 
         //Move the camera based on current rotation of the target and the original offset
         float desiredYAngle = pivot.eulerAngles.y;
         float desiredXAngle = pivot.eulerAngles.x;
         Quaternion rotation = Quaternion.Euler(desiredXAngle, desiredYAngle, 0);
         transform.position = target.position - (rotation * offset);
 
         if (transform.position.y < target.position.y)
             transform.position = new Vector3(transform.position.x, target.position.y - 0.5f, transform.position.z);
 
         transform.LookAt(target.transform);
     }
 }
 
              Your answer
 
             Follow this Question
Related Questions
i have to clamp a third person camera,I am trying to make a third person camera clamp. 0 Answers
TPS Camera roll ball 0 Answers
Cylinder Ground Collision 0 Answers
3d drawing based on movable planes? 0 Answers
3rd person camera controls 3 Answers