From bea7d61fd9d9cafa43cdc313780257eea09a190b Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 6 Oct 2020 15:43:47 -0400 Subject: Improve the Vector2 rotated code in C# --- modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'modules/mono') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 3dff37279b..d536b14eac 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -437,8 +437,11 @@ namespace Godot /// The rotated vector. public Vector2 Rotated(real_t phi) { - real_t rads = Angle() + phi; - return new Vector2(Mathf.Cos(rads), Mathf.Sin(rads)) * Length(); + real_t sine = Mathf.Sin(phi); + real_t cosi = Mathf.Cos(phi); + return new Vector2( + x * cosi - y * sine, + x * sine + y * cosi); } /// -- cgit v1.2.3