- Home /
Question by
Alexey F · Aug 14, 2015 at 05:45 AM ·
rotationjavascriptvoidmathf.clamp
how to clamp a void operator properly
Hi, i have an object that has a z rotation that should be clamped to 45 degrees each side. The problem is that transorm.Rotate returns nothing and im a bit stuck how to clamp it properly. will appreciate any help.
Thanks in advance.
#pragma strict
public var speedModifier: float;
public var speed : float = 0;
var arm : armScript;
public var position : Vector3;
function Update (){
var armAngle: float = arm.angle;
if (armAngle > 0.42){
speed = -20;}
else {speed = 20;};
transform.Rotate(Vector3.back, speed * Time.deltaTime);
GetComponent.<Rigidbody2D>().velocity.x = transform.rotation.z * speedModifier;
transform.position = new Vector3
(
Mathf.Clamp (transform.position.x, -2.2,2.2), 0.0f
);
}
Comment
Try looking up things like "unity limit rotation."
The question by itself doesn't really make any sense. You clamp numbers. You can't clamp an operator or function. If you have a number before or after using it, you can clamp that.
If you're getting the error about not being able to change x through an accessor, on one 22, look up how to fix that (try a search on the error message.)
Answer by RLin · Aug 14, 2015 at 07:40 PM
You can just check the rotation before hand:
if(transform.eulerAngles.x < 45 && transform.eulerAngles.x > -45){
//rotate stuff
}
Your answer
