forked from Clones/Controlify
✏️ Greatly improve gyro control
This commit is contained in:
@ -11,6 +11,8 @@ public class GamepadConfig extends ControllerConfig {
|
||||
public float gyroLookSensitivity = 0f;
|
||||
public boolean gyroRequiresButton = true;
|
||||
public boolean flickStick = false;
|
||||
public boolean invertGyroX = false;
|
||||
public boolean invertGyroY = false;
|
||||
|
||||
public BuiltinGamepadTheme theme = BuiltinGamepadTheme.DEFAULT;
|
||||
|
||||
|
@ -85,7 +85,9 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
|
||||
}
|
||||
}
|
||||
|
||||
GamepadState.GyroState gyroState = drivers.gyroDriver().getGyroState();
|
||||
// todo: make this configurable
|
||||
GamepadState.GyroState gyroState = drivers.gyroDriver().getGyroState().deadzone(0.05f);
|
||||
this.absoluteGyro = this.absoluteGyro.add(gyroState);
|
||||
|
||||
state = new GamepadState(deadzoneAxesState, basicState.axes(), basicState.buttons(), gyroState, absoluteGyro);
|
||||
}
|
||||
|
@ -209,5 +209,13 @@ public final class GamepadState implements ControllerState {
|
||||
public GyroState add(GyroState other) {
|
||||
return new GyroState(pitch + other.pitch, yaw + other.yaw, roll + other.roll);
|
||||
}
|
||||
|
||||
public GyroState deadzone(float deadzone) {
|
||||
return new GyroState(
|
||||
Math.max(pitch - deadzone, 0) + Math.min(pitch + deadzone, 0),
|
||||
Math.max(yaw - deadzone, 0) + Math.min(yaw + deadzone, 0),
|
||||
Math.max(roll - deadzone, 0) + Math.min(roll + deadzone, 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user