- Home /
Question by
gnp89 · May 28, 2013 at 02:57 AM ·
rotatelookatlookrotationalign
Align transform Y axis to -Physics.gravity
I've been trying to align a transform's Y axis to -Physics.gravity vector but can't get it right. I've tried transform.LookAt, Quaternion.LookRotation, but I need something that doesn't need a forward vector. I'm having problems when I try LookAt with the forward and the up vectors being in opposite directions. Any ideas?
Comment
Best Answer
Answer by robertbu · May 28, 2013 at 03:02 AM
Try this:
var q = Quaternion.FromToRotation(transform.up, -Physics.gravity);
transform.rotation = q * transform.rotation;