Hey.
Ther’s a way to limit the angles of rotation with transform.rotate? Can someone suggest me an example? I tried this but not work. I also tried to find some old question in unity-answers but nothing.
Thanks a lot.
public GameObject[] arm;
float speedUp;
float speedDown;
Vector3 StartPosition;
void Awake()
{
speedUp = 80f;
speedDown = 60f;
}
// Update is called once per frame
void Update () {
//go up
if (Input.GetKey (KeyCode.Z)) {
arm[0].transform.Rotate(Vector3.right * Time.deltaTime*speedUp);
if(transform.Rotate > 50) //rotation limits
{
transform.Rotate = 50;
}
}
//go down
if (Input.GetKey (KeyCode.X)) {
arm[0].transform.Rotate(-Vector3.right * Time.deltaTime*speedDown);
}
}
where the transform.localRotation.x in the brackets is your current value, then it restricts it between your max and min values. You can set them with floats or integers.
Correct me if I’m wrong though, I myself am trying to get a local rotation restriction going too