Im using the following to rotate my object roughly 180 degres:
rotation = Quaternion.AngleAxis( Random.Range(150, 200), transform.up );
I was just wondering what could I use to rotate it 45 degres towards the sky (as if it was taking off)
Thanks
Im using the following to rotate my object roughly 180 degres:
rotation = Quaternion.AngleAxis( Random.Range(150, 200), transform.up );
I was just wondering what could I use to rotate it 45 degres towards the sky (as if it was taking off)
Thanks
anyone?
To tell you the truth I’ve not understand very much what you want to do, but to rotate a transform by some degrees on a precise axis you could use the eulerAngles property.
As example (C# code given)
transform.eulerAngles = new Vector3 (90f, 0f, 0f);
will rotate the associated transform by 90 degrees on x axis.
If you don’t care about snaping to the new rotation, you can just use the same way you turned 180 degrees. Just change transform.up to transform.right (or Vector3.right).
If you want it to rotate smoothly, you can either use animation:
keyframe the rotation of the X or Z axis at 0 degrees, and then at 45 degrees after a few seconds, and then just play the animation at the desired time)
Or code… Many ways to do this. This is one of the simplest:
private var qFrom;
private var qTo;
public var fSpeed: float = 1.0;
function Start()
{
qFrom = transform.rotation;
qTo = Quaternion.Euler(transform.rotation.eulerAngles.x + 45,
transform.rotation.eulerAngles.y,
transform.rotation.eulerAngles.z);
}
function Update ()
{
transform.rotation =
Quaternion.Lerp (qFrom, qTo, Time.time * fSpeed);
Debug.Log(transform.rotation.eulerAngles);
}
Note that I assume your object is parallel to the ground. This code will ADD 45 degrees to the x axis… Easily fixed, thought, if that is not your intention.