From b3c9bd456186ccec036cd7710d584551139fbf16 Mon Sep 17 00:00:00 2001 From: RoboPhred Date: Sun, 26 Jul 2020 10:21:44 -0700 Subject: [PATCH] Use minmax when combining axes with game to avoid halfing input --- src/OrientationInjector.cs | 2 +- src/ThrustInjector.cs | 2 +- src/VectorUtils.cs | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/OrientationInjector.cs b/src/OrientationInjector.cs index e0b85c0..f50d606 100644 --- a/src/OrientationInjector.cs +++ b/src/OrientationInjector.cs @@ -48,7 +48,7 @@ static Vector3 ApplySixAxisRotation(Vector3 vector) { // TODO: Merge our input with existing input var rotation = new Vector3(InputHandler.RZ, InputHandler.RX, -InputHandler.RY); - return VectorUtils.Average(rotation, vector); + return VectorUtils.Clamp(rotation + vector, -1, 1); } } } diff --git a/src/ThrustInjector.cs b/src/ThrustInjector.cs index 9ae14f1..c84e01d 100644 --- a/src/ThrustInjector.cs +++ b/src/ThrustInjector.cs @@ -50,7 +50,7 @@ static Vector3 ApplySixAxisTranslation(Vector3 vector) { // var translation = new Vector3(-InputHandler.X, -InputHandler.Z, InputHandler.Y); var translation = new Vector3(InputHandler.X, -InputHandler.Z, -InputHandler.Y); - return VectorUtils.Average(translation, vector); + return VectorUtils.Clamp(translation + vector, -1, 1); } } } diff --git a/src/VectorUtils.cs b/src/VectorUtils.cs index 1550c15..cb77ab0 100644 --- a/src/VectorUtils.cs +++ b/src/VectorUtils.cs @@ -14,5 +14,15 @@ public static Vector3 Average(Vector3 a, Vector3 b) z = (a.z + b.z) / 2.0f }; } + + public static Vector3 Clamp(Vector3 vector, float min, float max) + { + return new Vector3 + { + x = Mathf.Clamp(vector.x, min, max), + y = Mathf.Clamp(vector.y, min, max), + z = Mathf.Clamp(vector.z, min, max) + }; + } } } \ No newline at end of file