mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-07-31 07:48:52 -04:00
Implement controller joystick deadzone (#5354)
* Implement controller joystick deadzone * Triggers keep a fixed deadzone
This commit is contained in:
@@ -36,6 +36,12 @@ public static class Preferences
|
||||
[ConVar( "controller_look_speed_pitch", ConVarFlags.Protected, Help = "How fast the camera turns vertically when the stick is pushed all the way up/down (deg/s)", Saved = true, Min = 0.1f, Max = 360.0f )]
|
||||
public static float ControllerLookPitchSpeed { get; internal set; } = 160.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The percentage of joystick travel ignored around the neutral position.
|
||||
/// </summary>
|
||||
[ConVar( "controller_joystick_deadzone", ConVarFlags.Protected, Help = "Percentage of joystick travel ignored around the neutral position", Saved = true, Min = 0.0f, Max = 50.0f )]
|
||||
public static float ControllerJoystickDeadzone { get; internal set; } = 12.5f;
|
||||
|
||||
[ConVar( "controller_analog_speed", ConVarFlags.Protected, Help = "How fast the left joystick moves, for stuff like the virtual cursor in menus", Saved = true, Min = 0.1f, Max = 360.0f )]
|
||||
internal static float ControllerAnalogSpeed { get; set; } = 2.0f;
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@ internal sealed partial class Controller
|
||||
|
||||
List<InputAxis> ControllerAxes { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Triggers always use a fixed deadzone, they're not affected by <see cref="Preferences.ControllerJoystickDeadzone"/>.
|
||||
/// </summary>
|
||||
const float TriggerDeadzone = 0.125f;
|
||||
|
||||
/// <summary>
|
||||
/// Get an axis
|
||||
/// </summary>
|
||||
@@ -44,9 +49,10 @@ internal sealed partial class Controller
|
||||
float flValue = inputValue;
|
||||
float normalizedAxis = flValue.Remap( Controller.AXIS_RANGE.x, Controller.AXIS_RANGE.y, -1, 1 );
|
||||
|
||||
// 12.5% deadzone
|
||||
// todo: make this modifiable
|
||||
var deadzone = 0.125f;
|
||||
var deadzone = axis < NativeEngine.GameControllerAxis.TriggerLeft
|
||||
? Preferences.ControllerJoystickDeadzone / 100.0f
|
||||
: TriggerDeadzone;
|
||||
|
||||
if ( MathF.Abs( normalizedAxis ) <= deadzone ) normalizedAxis = 0f;
|
||||
|
||||
if ( normalizedAxis > 0f )
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
<div class="is-label">Look Pitch Speed</div>
|
||||
<SliderControl Min=@(0) Max=@(360) Value:bind=@ControllerLookSpeedPitch ShowTextEntry="@true"></SliderControl>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<div class="is-label">Joystick Deadzone (%)</div>
|
||||
<SliderControl Min=@(0) Max=@(50) Step=@(0.5f) Value:bind=@ControllerJoystickDeadzone ShowTextEntry="@true"></SliderControl>
|
||||
</row>
|
||||
</div>
|
||||
|
||||
<SettingsFooter OnCancel=@OnCancel OnRestore=@OnRestore OnApply=@OnApply></SettingsFooter>
|
||||
@@ -50,6 +55,7 @@
|
||||
|
||||
public float ControllerLookSpeedYaw { get; set; }
|
||||
public float ControllerLookSpeedPitch { get; set; }
|
||||
public float ControllerJoystickDeadzone { get; set; }
|
||||
|
||||
public bool InvertMousePitch { get; set; }
|
||||
public bool InvertMouseYaw { get; set; }
|
||||
@@ -81,6 +87,7 @@
|
||||
ConsoleSystem.SetValue("sensitivity", 5);
|
||||
ConsoleSystem.SetValue("controller_look_speed_yaw", 270);
|
||||
ConsoleSystem.SetValue("controller_look_speed_pitch", 160);
|
||||
ConsoleSystem.SetValue("controller_joystick_deadzone", 12.5f);
|
||||
ConsoleSystem.SetValue("mouse_pitch_inverted", false);
|
||||
ConsoleSystem.SetValue("mouse_yaw_inverted", false);
|
||||
}
|
||||
@@ -90,6 +97,7 @@
|
||||
MouseSensitivity = ConsoleSystem.GetValue("sensitivity").ToFloat();
|
||||
ControllerLookSpeedYaw = ConsoleSystem.GetValue("controller_look_speed_yaw").ToFloat();
|
||||
ControllerLookSpeedPitch = ConsoleSystem.GetValue("controller_look_speed_pitch").ToFloat();
|
||||
ControllerJoystickDeadzone = ConsoleSystem.GetValue("controller_joystick_deadzone").ToFloat();
|
||||
InvertMousePitch = ConsoleSystem.GetValue("mouse_pitch_inverted").ToBool();
|
||||
InvertMouseYaw = ConsoleSystem.GetValue("mouse_yaw_inverted").ToBool();
|
||||
}
|
||||
@@ -99,6 +107,7 @@
|
||||
ConsoleSystem.SetValue( "sensitivity", MouseSensitivity );
|
||||
ConsoleSystem.SetValue( "controller_look_speed_yaw", ControllerLookSpeedYaw );
|
||||
ConsoleSystem.SetValue( "controller_look_speed_pitch", ControllerLookSpeedPitch );
|
||||
ConsoleSystem.SetValue( "controller_joystick_deadzone", ControllerJoystickDeadzone );
|
||||
ConsoleSystem.SetValue( "mouse_pitch_inverted", InvertMousePitch );
|
||||
ConsoleSystem.SetValue( "mouse_yaw_inverted", InvertMouseYaw );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user