diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-10-06 23:45:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 23:45:15 +0200 |
commit | e93af13959e2840e6fed58fb79ec4f7b9fdfec6a (patch) | |
tree | 764662a4539de501e24fdbc97e3580f533a7ba7c | |
parent | 07112b92a85de9b2134f3208149b295f871d3642 (diff) | |
parent | bea7d61fd9d9cafa43cdc313780257eea09a190b (diff) |
Merge pull request #42606 from aaronfranke/cs-vec2-rotated
Improve the Vector2 rotated code in C#
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs | 7 |
1 files changed, 5 insertions, 2 deletions
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 /// <returns>The rotated vector.</returns> 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); } /// <summary> |