diff --git a/src/raymath.h b/src/raymath.h index 34db2d885..9175bbc21 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -307,9 +307,13 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2) } // Calculate angle from two vectors +// Parameters need to be normalized RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { - float result = -acos(v1.x*v2.x + v1.y*v2.y); + float dotProduct = v1.x*v2.x + v1.y*v2.y; + + float t = dotProduct < -1 ? -1 : dotProduct; + float result = acos(t > max ? max : t;); return result; }