From 6191fde25a19f7ada07d6ba14787a27569f443de Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 9 Aug 2025 16:09:54 -0500 Subject: [PATCH] Fix: apply steering input properly The ship in Asteroids isn't expected to spin up while holding a steering direction, but that's exactly what I just made it do. Fix that problem by assigning, not accumulating, the angular velocity for the ship. --- src/config.rs | 2 +- src/lib.rs | 6 ++++-- src/ship.rs | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index bfc8fb8..c8a2fbe 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,6 +13,6 @@ pub(crate) const ASTEROID_SMALL_COLOR: Color = Color::srgb(1.0, 0., 0.); // TODO: asteroid medium & large pub(crate) const SHIP_THRUST: f32 = 1.0; -pub(crate) const SHIP_ROTATION: f32 = 0.1; // +/- rotation speed in... radians per frame +pub(crate) const SHIP_ROTATION: f32 = 4.0; // +/- rotation speed in... radians per frame pub const RNG_SEED: [u8; 32] = *b"12345678909876543210123456789098"; diff --git a/src/lib.rs b/src/lib.rs index 1a752fd..7b0335b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -280,9 +280,11 @@ fn input_ship_rotation( }; if keyboard_input.pressed(KeyCode::KeyA) { - angular_vel.0 += SHIP_ROTATION; + angular_vel.0 = SHIP_ROTATION; } else if keyboard_input.pressed(KeyCode::KeyD) { - angular_vel.0 -= SHIP_ROTATION; + angular_vel.0 = -SHIP_ROTATION; + } else { + angular_vel.0 = 0.0; } } diff --git a/src/ship.rs b/src/ship.rs index aafcf3d..b49a6e2 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,5 +1,6 @@ use crate::{ - physics::{Velocity, Wrapping}, AngularVelocity, GameAssets + AngularVelocity, GameAssets, + physics::{Velocity, Wrapping}, }; use bevy::prelude::*;