add Space key to slow down
This commit is contained in:
parent
56a9fd766d
commit
9c2b2e4e0f
|
@ -29,6 +29,7 @@ pub struct CameraController {
|
|||
pub key_up: KeyCode,
|
||||
pub key_down: KeyCode,
|
||||
pub key_run: KeyCode,
|
||||
pub key_stop: KeyCode,
|
||||
pub mouse_key_cursor_grab: MouseButton,
|
||||
pub keyboard_key_toggle_cursor_grab: KeyCode,
|
||||
pub move_speed: f32,
|
||||
|
@ -51,10 +52,11 @@ impl Default for CameraController {
|
|||
key_up: KeyCode::ShiftLeft,
|
||||
key_down: KeyCode::ControlLeft,
|
||||
key_run: KeyCode::KeyR,
|
||||
key_stop: KeyCode::Space,
|
||||
mouse_key_cursor_grab: MouseButton::Left,
|
||||
keyboard_key_toggle_cursor_grab: KeyCode::KeyM,
|
||||
move_speed: 1.0,
|
||||
friction: 0.0,
|
||||
friction: 0.1,
|
||||
pitch: 0.0,
|
||||
yaw: 0.0,
|
||||
velocity: Vec3::ZERO,
|
||||
|
@ -157,13 +159,18 @@ fn run_camera_controller(
|
|||
}
|
||||
let cursor_grab = *mouse_cursor_grab || *toggle_cursor_grab;
|
||||
|
||||
let friction = if key_input.pressed(controller.key_stop) {
|
||||
controller.friction.clamp(0.0, 1.0)
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
// Apply movement update
|
||||
if axis_input != Vec3::ZERO {
|
||||
let new_velocity = controller.velocity + axis_input.normalize() * controller.move_speed;
|
||||
controller.velocity = new_velocity;
|
||||
play_thruster_sound = true;
|
||||
} else {
|
||||
let friction = controller.friction.clamp(0.0, 1.0);
|
||||
controller.velocity *= 1.0 - friction;
|
||||
if controller.velocity.length_squared() < 1e-6 {
|
||||
controller.velocity = Vec3::ZERO;
|
||||
|
|
Loading…
Reference in a new issue