Compass directions (N, E, S, W)

Hey there,

is there a way to get the directions North, East, South and West depending where the player is looking at?

I tried it with the rotation but then noticed that it changes if the player moves, of course.

Kindest Regards,
Matt

Asssuming your character is on the XZ plane with positive ā€˜Zā€™ as north:

#pragma strict

function Update () {
	var v = transform.forward;
	v.y = 0;
	v.Normalize();
	
	if (Vector3.Angle(v, Vector3.forward) <= 45.0) {
		Debug.Log("North");
	}
	else if (Vector3.Angle(v, Vector3.right) <= 45.0) {
		Debug.Log("East");
	}
	else if (Vector3.Angle(v, Vector3.back) <= 45.0) {
		Debug.Log("South");
	}
	else {
		Debug.Log("West");
	}
}

Depending your your use, there are other, perhaps more efficient ways.