Skip to content

Commit

Permalink
Use minmax when combining axes with game to avoid halfing input
Browse files Browse the repository at this point in the history
  • Loading branch information
RoboPhred committed Jul 26, 2020
1 parent a63af30 commit b3c9bd4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/OrientationInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ThrustInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions src/VectorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}
}
}

0 comments on commit b3c9bd4

Please sign in to comment.