Hi there,
I have some problems with limitting the X-axis and the Z-axis.
I have a tray with a maze on it, on my scene, and i would like to limit the rotation of the tray.
Basically, i receive X and Z values from an external device, a RaspBerry actually, communicating with a TCP Server, and updating the rotation of the tray every seconds.
My problem here is just the rotation part, wich i want to limit from -30 to 30 for example.
Here’s the script attached to the tray:
public class ControlTray : MonoBehaviour
{
public float speedRot;
private float x;
private float z;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody> ();
ServerTCP.Level = 0;
}
void FixedUpdate()
{
x = ServerTCP.x * speedRot * Time.deltaTime;
z = ServerTCP.z * speedRot * Time.deltaTime;
Vector3 Moves= new Vector3(x,0.0f,z);
rb.transform.Rotate (Moves);
}
}
I saw other topic trating the same subject, but none of them actually helped me.
I mean, i saw that Mathf.Clamp seems to be the option i need, but i really didn’t understand how to use it.
I’m really looking forwards your answers,
Thanks in advance.
Bryan.