Make keyboard control forces, not velocities

The keyboard input should apply a force, not modify the velocity. Right
now, there is no Mass component, but in the future there might be. I've
just fixed a broken physics integrator made by bad assumptions, too, so
I'm goig to do this for consistency if nothing else.
This commit is contained in:
2025-09-02 16:08:18 -05:00
parent b3cf47e684
commit 8b61d38636

View File

@@ -120,13 +120,13 @@ fn turn_if_edge(
fn check_keyboard( fn check_keyboard(
keyboard_input: Res<ButtonInput<KeyCode>>, keyboard_input: Res<ButtonInput<KeyCode>>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>, mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
mut query: Query<&mut Velocity, With<PlayerBoid>>, mut query: Query<&mut Force, With<PlayerBoid>>,
) { ) {
if keyboard_input.just_pressed(KeyCode::KeyQ) { if keyboard_input.just_pressed(KeyCode::KeyQ) {
app_exit_events.send(bevy::app::AppExit::Success); app_exit_events.send(bevy::app::AppExit::Success);
} }
let mut pvelocity = query let mut impulse = query
.single_mut() .single_mut()
.expect("[birdoids_plugin::check_keyboard()] ->> There seems to be more than one player... How did that happen?"); .expect("[birdoids_plugin::check_keyboard()] ->> There seems to be more than one player... How did that happen?");
let mut dir = Vec2::ZERO; let mut dir = Vec2::ZERO;
@@ -143,7 +143,7 @@ fn check_keyboard(
dir.y += 1.0; dir.y += 1.0;
} }
**pvelocity += dir.extend(0.0); **impulse += dir.extend(0.0) * 50.0;
} }
fn cohesion( fn cohesion(