- Home /
Question by
NinjaRubberBand · Jul 26, 2014 at 01:08 PM ·
rotationtransform
transform.rotation doesn't stop
What i want in this script i made is that my object which is a tire, needs to rotate the to side when pressing "a". When it then hits 16 if(transform.rotation.z > 16)
Then it stops. transform.rotation.z = 16; But somehow it continues to rotate and doesn't stop at 16. If you have any questions, ill answer them.
#pragma strict
var speed : float;
var turnSpeed = 0.0;
var turnMotion = 0;
function Start () {
}
function Update () {
speed = gameObject.Find("Rubber").GetComponent(Movement).speed;
transform.Rotate(Vector3(turnSpeed,0,0) * Time.deltaTime);
turnSpeed = speed * 20;
if(transform.rotation.z > 16) {
transform.rotation.z = 16; }
if(Input.GetKey("a")) {
transform.Rotate(Vector3(0,0,turnMotion) * Time.deltaTime);
}
}
Comment
Answer by Hullu · Jul 26, 2014 at 01:21 PM
Im not sure what you are trying to do, but here is fix for your current code:
Change
if(transform.rotation.z > 16) {
transform.rotation.z = 16; }
To
if(transform.localEulerAngles.z > 16) {
transform.localEulerAngles.z = 16; }