S
S
Sputnik Upitera2020-10-05 03:34:35
C++ / C#
Sputnik Upitera, 2020-10-05 03:34:35

How to limit the rotation of an object when using transform.Rotate()?

Good afternoon. I'm trying to limit the rotation of an object along the x axis .
The rotation is carried out as follows:

float moveVertical = Input.GetAxis("Vertical");
transform.Rotate(moveVertical * rotationRate * Time.deltaTime, 0, 0);

I tried to do it like this:
if( transform.rotation.x > -89f && tranform.rotation.x < 89f) 
{
   transform.Rotate(moveVertical * rotationRate * Time.deltaTime, 0, 0); 
}

But then Unity breaks down, and PlayMode doesn't turn on at all...
You have to restart the program through the task manager.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-10-05
@DanielMcRon

Mathf.Clamp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question