- Home /
Best Answer
Answer by Mike 3 · May 05, 2011 at 06:11 AM
transform.rotation = Quaternion.LookRotation(directionVector);
Not sure to understand the question, but you can try Quaternion.FromToRotation() to change some direction into another, or differently said, to change the object's reference axis.
For example :
transform.rotation = Quaternion.LookRotation(directionVector) * Quaternion.FromToRotation(Vector3.right, Vector3.forward);
I still haven't found an answer to that very question, ina
This worked for me;
private Quaternion _facing;
void Start () {
//Grab the offset at the start.
//You could also make your own Quaternion but don't use Euler angles it just seems to break things.
_facing = transform.rotation;
}
void Update () {
var rotation = Quaternion.LookRotation(directionVector.normalized);
rotation *= _facing;
transform.rotation = rotation;
}
Answer by iwaldrop · Mar 23, 2012 at 08:42 AM
To rotate an object to face a desired orientation, perform the following on LateUpdate():
transform.Rotate(Vector3.right/up/forward, float);
ex:
void LateDraw() { this.transform.Rotate(Vector3.up, 90); }
this will set the rotation each frame to whatever you need it to be. The example illustrates a 90˚ since that's the rotation offset of most imports...