Hello everyone , i have a an object and i want to do limit to y axis im using javascript. How can i make it in 5-17 range ?
Thanks.
Hello everyone , i have a an object and i want to do limit to y axis im using javascript. How can i make it in 5-17 range ?
Thanks.
How about this?
function Update ()
{
if (CFInput.GetKey(KeyCode.W) && transform.position.y <15)
{
rigidbody.velocity.y = speed;
}
else if (CFInput.GetKey(KeyCode.S) && transform.position.y > 7)
{
rigidbody.velocity.y = speed *-1;
}
else
{
rigidbody.velocity.y = 0;
}
}
If your object is only rotating on the ‘y’ axis, you can do:
var euler = transform.eulerAngles;
euler.y = Mathf.Clamp(euler.y, 5.0, 17.0);
transform.eulerAngles = euler;
The problem is significantly more complicated if you are allowing rotation on multiple axes. I’d need to see your rotation code in order to advise.