I have an object that is basically going to be rotating either +180 or -180 degrees on either the x or z axis. Once a rotation occurs, the object will be free to go through another 180 degree rotation on either the x or z axis. (never both at the same time).
transform.localEulerAngles.x += 4;
Doesn’t work. I don’t understand why on the x axis gets stuck on the rotation at 90. Is it because of the order of rotations? Even if it did work I’m not sure how to handle the axis when a rotation occurs because the directions would be reversed I think. help?
so I’m guessing I could use…
transform.rotation *= Quaternion.AngleAxis(number, Vector3.back);
but the problem is now… the viewer has a locked perspective on the object. so when the viewer pushes the button A… the object will rotate clockwise on the x axis… but when the z axis flips the object. pushing A will cause the object to flip counter clockwise from the viewers perspective.
Aside from the Time.deltaTime. what is the difference between…
transform.Rotate(Vector3.back * Time.deltaTime);
and
transform.rotation *= Quaternion.AngleAxis(number, Vector3.back);
Also… I came up with this to solve my problem. It is really sloppy. It works. I couldn’t think of a good way to reduce the amount of code. Because the vectors don’t seem to multiply against itself or go through absolute values. So I could get it to reverse directions but when I did it also reversed the directions for the keys as well. So… Button S would flip it negatively. And then flip it positively.
Is there a smart way to reverse the direction of the vector when using a single var for the vector?
var zAxis:Vector3;
var xAxis:Vector3;
var special:float;
var seconds:float;
var rotateOnX: boolean;
var rotateOnZ: boolean;
var rotateOnXneg:boolean;
var rotateOnZneg:boolean;
function Awake()
{
zAxis = Vector3.forward;
xAxis = Vector3.right;
}
function Update () {
//transform.localEulerAngles.z += 4;
//why does z work fine but not x?
// transform.RotateAround (Vector3.zero, Vector3.up, 20 * Time.deltaTime);
//toBeRotated = Vector3(0, 5, 0);
//rotateVectorAboutX = Quaternion.AngleAxis(30, Vector3(1, 0, 0));
// special += 1;
//transform.rotation = Quaternion.AngleAxis(55, Vector3(special, 0, 0));
if(Input.GetKey("a"))
{
rotateOnZ=true;
if(zAxis == Vector3.forward)
{
zAxis = Vector3.back;
}
else
{
zAxis = Vector3.forward;
}
}
if(Input.GetKey("d"))
{
rotateOnZneg=true;
if(zAxis == Vector3.forward)
{
zAxis = Vector3.back;
}
else
{
zAxis = Vector3.forward;
}
}
if(Input.GetKey("w"))
{
rotateOnX=true;
if(xAxis == Vector3.left)
{
xAxis = Vector3.right;
}
else
{
xAxis = Vector3.left;
}
}
if(Input.GetKey("s"))
{
rotateOnXneg=true;
if(xAxis == Vector3.left)
{
xAxis = Vector3.right;
}
else
{
xAxis = Vector3.left;
}
}
if(rotateOnX)
{
seconds = Time.deltaTime + seconds;
if (seconds<2)
{
transform.rotation *= Quaternion.AngleAxis(special, zAxis);
}
else
{
rotateOnX=false;
seconds -= seconds;
}
}
if(rotateOnXneg)
{
seconds = Time.deltaTime + seconds;
if (seconds<2)
{
transform.rotation *= Quaternion.AngleAxis(special, zAxis*-1);
}
else
{
rotateOnXneg=false;
seconds -= seconds;
}
}
if(rotateOnZ)
{
seconds = Time.deltaTime + seconds;
if (seconds<2)
{
transform.rotation *= Quaternion.AngleAxis(special, xAxis);
}
else
{
rotateOnZ=false;
seconds -= seconds;
}
}
if(rotateOnZneg)
{
seconds = Time.deltaTime + seconds;
if (seconds<2)
{
transform.rotation *= Quaternion.AngleAxis(special, xAxis*-1);
}
else
{
rotateOnZneg=false;
seconds -= seconds;
}
}
So… How do you rotate 180 perfectly with vectors? cause… the below code is about 10 degrees off all the time.
seconds = Time.deltaTime + seconds;
if (seconds<.5)
{
transform.Rotate(xAxis * Time.deltaTime*360);
//transform.rotation *= Quaternion.AngleAxis(special, xAxis);
}
edit: nevermind. sigh…
transform.Rotate(Vector3(4,0,0));