in 2D space how can i calculate angle which between 2 vector?
Unity already has a method that calculates the angle between two vectors (Vector2.Angle). An alternative is to calculate the dot product between the two directions. If both vectors are normalized the result is the cosine of your angle:
Vector2 forward;
Vector2 vector1;
Vector2 vector2;
Vector2 dir = vector2 - vector1;
// first solution
float angle = Vector2.Angle(forward, dir);
// second solution
float angle = Mathf.Acos(Vector2.Dot(forward.normalized, dir.normalized));
Keep in mind that the angle is always positive. If you need an angle based on the orientation of the two vectors you have to determine the order of the two direction vectors. The cross product is the easiest way:
Vector tmp = Vector3.Cross(forward, dir);
if (tmp.z > 0)
// dir is above forward
else
// dir is below forward
That’s all ^^.
Trig.
This method only works if when you refer to forward you actually mean the Vector2.right or equivalent Vector3.right. In other words the angle between a vector and the positive x-axis
If you start at Vec1, and Vec2 is the direction you want the angle first
//First you have to translate you Vec2 to be a direction vector in world space
//You can do this by subtracting its start point from its end point.
Vector2 vecD= vec2 - vec1;
//This will get you the answer in radians
float b = Mathf.Acos( vecD.x/ vecD.magnitude);
//This converts to degrees
float bDegrees = Mathf.Deg2Rad * b;
//Optional if you want your angles going below the X-axis to be negative
//This only really makes sense when working in degrees
if(vecD.y <0) {
float bDegrees -= 360;
}