I want to be able to have something to rotate to look at something, but I don't know how to make it accurate. I only want it to rotate on the Z axis. Any good way I could do this?
asked Sep 11 '11 at 01:42 AM
You can calculate the direction of the target and zero the z coordinate - this restricts the direction to the XY plane. Then you can calculate a Quaternion.FromToRotation from what you consider your forward direction to the target - if the forward direction of your object is the X axis, for instance, you should use Vector3.right as from direction:
var target: Transform; ... var atDir = target.position-transform.position; atDir.z = 0; // restricts direction to the XY plane transform.rotation = Quaternion.FromToRotation(Vector3.right, atDir); ...
answered Sep 11 '11 at 02:06 AM