From 5d4f17da3a077951fa2c54cd656455b79476e6cb Mon Sep 17 00:00:00 2001 From: Antonis Geralis <43617260+planetis-m@users.noreply.github.com> Date: Thu, 15 Dec 2022 12:39:26 +0200 Subject: [PATCH] Fix vector2angle --- src/raymath.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; }