P
P
Pavel Subbotin2021-02-04 10:21:32
Unity
Pavel Subbotin, 2021-02-04 10:21:32

Why doesn't the Cinemachine camera rotate?

In general, I did everything as in this lesson: https://www.youtube.com/watch?v=537B1kJp9YQ , but my camera script does not work.
The code:

public Vector2 _look;
    public float rotationPower = 3f;
    public GameObject target;
    private void Update()
    {
        target.transform.rotation *= Quaternion.AngleAxis(_look.x * rotationPower, Vector3.up);

        target.transform.rotation *= Quaternion.AngleAxis(_look.y * rotationPower, Vector3.right);

        var angles = target.transform.localEulerAngles;
        angles.z = 0;

        var angle = target.transform.localEulerAngles.x;
        if (angle > 180 && angle < 340)
        {
            angles.x = 340;
        }
        else if(angle < 180 && angle > 40)
        {
            angles.x = 40;
        }


        target.transform.localEulerAngles = angles;

        transform.rotation = Quaternion.Euler(0, target.transform.rotation.eulerAngles.y, 0);
        target.transform.localEulerAngles = new Vector3(angles.x, 0, 0);
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question