quaternion.slerp doing 180 even though its supposed to do -30

am trying to make the camera slerp to -30 on the x axis even though it keeps doing a 180, ive tried local rotation same thing ive tried lerp same thing i dont know why its not working, heres the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rotatecam : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {

        myInput();
    }

    void myInput()
    {
        if (Input.GetKey("w"))
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, new Quaternion(-30, 0, 0, 1), 5 * Time.deltaTime);
        }
    }

sorry its not 180 its -180

Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.

There’s even a dedicated forum: Unity Engine - Unity Discussions

Otherwise if you want to proceed with the above, here’s some relevant notes:

All about Euler angles, by StarManta:

https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html

Notes on clamping camera rotation and NOT using .eulerAngles because of gimbal lock:

How to instantly see gimbal lock for yourself:

ok thanks

i used quaternion.euler with mathf and it works!

1 Like