diff options
author | Giacom <giacomand@gmail.com> | 2019-04-07 22:40:56 +0100 |
---|---|---|
committer | Giacom <giacomand@gmail.com> | 2019-05-28 11:39:35 +0100 |
commit | c00427add34f505cff275ea33423f1053423d646 (patch) | |
tree | 9fef14ccadd219e7050de28394a53e72209268ce /modules/mono/glue | |
parent | 252c841d7ff5d770e8d2819e4f7955363410744b (diff) |
Added move_toward functions for float, Vector2 and Vector3
Diffstat (limited to 'modules/mono/glue')
-rw-r--r-- | modules/mono/glue/Managed/Files/Mathf.cs | 5 | ||||
-rw-r--r-- | modules/mono/glue/Managed/Files/Vector2.cs | 8 | ||||
-rw-r--r-- | modules/mono/glue/Managed/Files/Vector3.cs | 8 |
3 files changed, 21 insertions, 0 deletions
diff --git a/modules/mono/glue/Managed/Files/Mathf.cs b/modules/mono/glue/Managed/Files/Mathf.cs index 8fb8730b88..2d8c63fe7f 100644 --- a/modules/mono/glue/Managed/Files/Mathf.cs +++ b/modules/mono/glue/Managed/Files/Mathf.cs @@ -210,6 +210,11 @@ namespace Godot return a < b ? a : b; } + public static real_t MoveToward(real_t from, real_t to, real_t delta) + { + return Abs(to - from) <= delta ? to : from + Sign(to - from) * delta; + } + public static int NearestPo2(int value) { value--; diff --git a/modules/mono/glue/Managed/Files/Vector2.cs b/modules/mono/glue/Managed/Files/Vector2.cs index bb1950e1a8..a7f26283a7 100644 --- a/modules/mono/glue/Managed/Files/Vector2.cs +++ b/modules/mono/glue/Managed/Files/Vector2.cs @@ -186,6 +186,14 @@ namespace Godot return res; } + public Vector2 MoveToward(Vector2 to, real_t delta) + { + var v = this; + var vd = to - v; + var len = vd.Length(); + return len <= delta || len < Mathf.Epsilon ? to : v + vd / len * delta; + } + public Vector2 Normalized() { var v = this; diff --git a/modules/mono/glue/Managed/Files/Vector3.cs b/modules/mono/glue/Managed/Files/Vector3.cs index 283cb6341a..16803ae55c 100644 --- a/modules/mono/glue/Managed/Files/Vector3.cs +++ b/modules/mono/glue/Managed/Files/Vector3.cs @@ -190,6 +190,14 @@ namespace Godot ); } + public Vector3 MoveToward(Vector3 to, real_t delta) + { + var v = this; + var vd = to - v; + var len = vd.Length(); + return len <= delta || len < Mathf.Epsilon ? to : v + vd / len * delta; + } + public Axis MaxAxis() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); |