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