I have a compass, which I would like to always head “north” (along the vector (0,0,-1)). To do this I’m using Quaternion.LookRotation(), but something is not right. The dial is pointing where I want it to point, but it is not rotating around it’s initial local Y-axis as I would want it to.
My code right now for this is:
using UnityEngine;
using System.Collections;
public class OrientCompassNorth : MonoBehaviour {
public Vector3 northDirection = new Vector3(0, 0, 1);
// Update is called once per frame
void LateUpdate () {
transform.rotation = Quaternion.LookRotation(northDirection,transform.parent.up.normalized);
}
void OnDrawGizmos ()
{
Gizmos.DrawLine (transform.parent.position, transform.parent.position + transform.parent.up.normalized * 2.0f);
}
}
Ingame, the compass then looks like this:

In the scene view, the compass looks like this:

For me, this means that the up-vector is as it should be, as the line is resembling what i feel is the correct axis to rotate around. But for some reason the dial gets a rotation of (42.3, 2.1, 3.1), which in the editor before runtime is (0, 0, 0)…
It should also be noted that the parent (the rest of the compass) is not aligned with any global planes.
I am looking for any explanation as to why it behaves like this or pointers/general comments of how Quaternion.LookRotation() works if I’m not using it right…