Vector3.Angle as dumb as it can be.

Picking holes while working on my proj, I discovered that Angle doesn’t return negative types of the euler angle, bump, I have to write:

float angle= Vector3.Angle(baryCenter.transform.position-transform.position,Vector3.up);
  if(transform.position.x>originalX)
	targetA.transform.rotation=Quaternion.Euler(new Vector3(0,0,-angle));
  else		
targetA.transform.rotation=Quaternion.Euler(new Vector3(0,0,angle));

I will take a look again in two years, I hope you’ll have fixed it :wink:

I also wonder why Vector3.Angle don’t return negative angle. Is it really a bug or there is a reason for not return negative value?

There are no negative numbers because the equation used to derive angles between vectors does not return negative numbers (arccos).

It’s basically, hold up any two arbitrary 3D vectors in space, here’s the angle between them.

have a look here:
http://forum.unity3d.com/threads/13785-Getting-the-angle-between-2-objects
especially the post of podperson is interesting.

the problem with negative angles is that you need to define a direction for them. if you have two points spread in 3d space and want to determine an angle from the origin which one should be marked the negative one? unity cant know that and would require an additional orientation information (your intended upvector for example) and additional computing time. so this solution is enough for most cases and if you need this additional information just make your own function with the hint in the link above.