Direction of angle

Hello!

I am trying to create a planet that uses a heightmap in a spherical manner. I have gotten it to read from an image using the grayscale for height alright but there is an issue.

Since Vector3.Angle does not pay attention to the direction of the angle I am getting a mirror image on my planet like so:

The last image being the heightmap.

Notice how testing is only on the heightmap once and on the planet twice.

Here is the code I am using ( run through every vertex in a sphere )

var vertDir = vertices[i].normalized;
var angleX = angleDir( Vector3(0,1,0), vertDir );
var angleY = angleDir( Vector3(1,0,0), vertDir );
var mapHeight = heightMap.GetPixel( angleX*heightMap.width,angleY*heightMap.height ).grayscale;
		
vertices[i] += vertDir*(mapHeight*20);

and the angle dir function

function angleDir( fwd: Vector3, targetDir: Vector3 )
{
	var ang = Vector3.Angle( targetDir, fwd );
 	return ang/360;
}

So long story short - how can I make unity get an angle from a clockwise direction rather than turning around and getting the shortest angle.

That’s an interesting problem. (I hate math but like seeing being applied). The Vector3.Angle I believe that will always return the closest angle. This is desirable in many situations. In your case, it feels more like dot product or something involving cosine (since they go from -1 to 1 relative to a vector, you can easily map half a circle). I found some answers that I will quote here:

Mathf.Acos(Vector3.Dot(vector1.normalized, vector2.normalized));

This one was from

/// <summary>
/// Determine the signed angle between two vectors, with normal 'n'
/// as the rotation axis.
/// </summary>

public static float AngleSigned(Vector3 v1, Vector3 v2, Vector3 n)
{
    return Mathf.Atan2(
        Vector3.Dot(n, Vector3.Cross(v1, v2)),
        Vector3.Dot(v1, v2)) * Mathf.Rad2Deg
    );
}

This one was from Tinus, at http://forum.unity3d.com/threads/51092-need-Vector3-Angle-to-return-a-negtive-or-relative-value. This one you need a normal to use as a reference. In your case, the normal can be the same as the orientation vector (1,0,0) or(0,1,0)

Quite busy to test them now, so I am blind posting it here.

Second solution worked, thank you so much!