Y
Y
Yugg02020-12-08 20:18:24
Unity
Yugg0, 2020-12-08 20:18:24

How to limit the rotation of an object in Unity3d?

There is a 3d object (let's say a cube), using the code:

if (isRotate == true)
        {
            transform.Rotate(Vector3.down * speedRotate * Time.deltaTime);
        }

        if (isRotate == false)
        {
            transform.Rotate(Vector3.up * speedRotate * Time.deltaTime);
        }


How to make a cube rotation limit, searched the entire Internet, nothing helps.

Tried:
if (transform.rotation.y > -90)
            {
                transform.rotation = Quaternion.Euler(0, -90f, 0);
            }

Nothing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nekit Medvedev, 2020-12-09
@NIKROTOS

You can try to draw a line and count deviations from it. Another option is to take the standard value and count the deviations and in each frame determine the maximum deviation available (to the edges), but this is too much code for this. The first option is better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question