try fix slow rotation drift

This commit is contained in:
2025-03-16 00:07:13 +01:00
parent 325066326e
commit f3597dcf0b

View File

@@ -31,6 +31,13 @@ pub fn plugin(app: &mut App) {
app.add_systems(Update, gamepad_connections.run_if(on_event::<GamepadEvent>));
}
fn clamp_vec2(v: Vec2, min: f32) -> Vec2 {
Vec2::new(
if v.x.abs() < min { 0. } else { v.x },
if v.y.abs() < min { 0. } else { v.y },
)
}
fn gamepad_controls(
mut commands: Commands,
gamepads: Query<(Entity, &Gamepad)>,
@@ -49,10 +56,9 @@ fn gamepad_controls(
.get(GamepadButton::RightTrigger2)
.unwrap_or_default();
const EPSILON: f32 = 0.015;
//8BitDo Ultimate wireless Controller for PC
let look_dir = if gamepad.vendor_id() == Some(11720) && gamepad.product_id() == Some(12306) {
const EPSILON: f32 = 0.015;
Vec2::new(
if rotate < 0.5 - EPSILON {
40. * (rotate - 0.5)
@@ -64,7 +70,7 @@ fn gamepad_controls(
0.,
)
} else {
gamepad.right_stick() * 40.
clamp_vec2(gamepad.right_stick(), 0.01) * 40.
};
let state = ControlState {
@@ -149,20 +155,26 @@ fn gamepad_connections(mut evr_gamepad: EventReader<GamepadEvent>) {
let GamepadEvent::Connection(ev_conn) = ev else {
continue;
};
match &ev_conn.connection {
GamepadConnection::Connected {
name,
vendor_id,
product_id,
} => {
info!(
"New gamepad connected: {:?}, name: {name}, vendor: {vendor_id:?}, product: {product_id:?}",
ev_conn.gamepad
);
}
GamepadConnection::Disconnected => {
info!("Lost connection with gamepad: {:?}", ev_conn.gamepad);
match ev {
GamepadEvent::Connection(connection) => match &connection.connection {
GamepadConnection::Connected {
name,
vendor_id,
product_id,
} => {
info!(
"New gamepad connected: {:?}, name: {name}, vendor: {vendor_id:?}, product: {product_id:?}",
ev_conn.gamepad
);
}
GamepadConnection::Disconnected => {
info!("Lost connection with gamepad: {:?}", ev_conn.gamepad);
}
},
GamepadEvent::Button(gamepad_button_changed_event) => {
info!("Gamepad Button: {:?}", gamepad_button_changed_event);
}
_ => {}
}
}
}