From 36c476b36e771210bfcb0977c2d2b3d55e114314 Mon Sep 17 00:00:00 2001 From: veins1 <19636663+veins1@users.noreply.github.com> Date: Wed, 14 Dec 2022 19:44:48 +0500 Subject: [PATCH] Vector2Angle fix for non-normalized vectors --- src/raymath.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/raymath.h b/src/raymath.h index 34db2d885..a853fdcc7 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -309,7 +309,9 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2) // Calculate angle from two vectors RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { - float result = -acos(v1.x*v2.x + v1.y*v2.y); + float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); + float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); + float result = -acos((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); return result; }