- Home /
Rotating only one axis ?
Hi, I'm quite new to Unity - I want to rotate a box's Y axis using transform.rotate, but I need the X/Z values to remain at 0. However when I apply the rotation, the X and Z values change too. Is there a way to prevent that?
I used that method....but the problem is it still rotates the X/Z as well - you can't see it in motion, but the values change. This isn't good for me because I need to keep the values at 0 so I can perform an IF statement for the object's X/Y rotation....
Why not just set them to zero then? Also, if you know they will be zero, why would you need an IF statement?
Answer by hirenkacha · Jun 25, 2013 at 11:29 AM
Try this
transform.Rotate(Vector3.up* Time.deltaTime);
Is your control cube static checked?? If it is then this may have caused the problem.
Answer by amphoterik · Jun 25, 2013 at 12:41 PM
You can do like hirenkacha said or you can do:
transform.Rotate(0, 1, 0);
They do basically the same thing. Hirenkacha's solution allows for smooth rotation regardless of computer performance (which is better). I am simply posting this solution as it shows what Vector3.up is actually doing.
I tried it but still the X/Z values change all the time. You can't see it in motion but you can see the values changing
are they just small changes? There will be some fluctuation unless you look the axis or manually set them to 0.
thing is I control the box, which rotates all the time. I want to remove the control when the box flips over because that causes weird behavior , And I need to make an IF statement for the other rotation values to deter$$anonymous$$e if the box has flipped over.
Answer by killer-zog · Jun 27, 2013 at 07:03 AM
this code is in js
#pragma strict
public var speed : float = 4.0;
function OnBecameVisible () {
enabled = true;
}
function OnBecameInvisible () {
enabled = false;
}
function Update () {
transform.Rotate( 0.0 , Time.deltaTime * speed , 0.0 );
}
just attached the script to the object and select the speed in the inspector view and you are good to go.
Your answer
Follow this Question
Related Questions
Rotating object on it's Y axis from pos 180 to 0... 2 Answers
Move and Rotate on a fixed axis? 1 Answer
How do I smoothly rotate a bone based on axis input? 0 Answers
how to reorient the axes ? 1 Answer
Spin an object 1 Answer