diff --git a/src/camera.rs b/src/camera.rs index 48ff140..3d7d4a6 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use bevy::input::mouse::MouseMotion; use bevy::window::PrimaryWindow; use std::f32::consts::*; -use crate::{settings, audio}; +use crate::{settings, audio, actor}; pub struct CameraControllerPlugin; @@ -35,7 +35,7 @@ impl Default for CameraController { enabled: true, initialized: false, sensitivity: 0.5, - move_speed: 1.0, + move_speed: 10.0, friction: 0.1, pitch: 1.0, // pitch=0/yaw=0 -> face sun yaw: 0.3, @@ -52,7 +52,7 @@ fn run_camera_controller( mut mouse_events: EventReader, key_input: Res>, thruster_sound_controller: Query<&AudioSink, With>, - mut query: Query<(&mut Transform, &mut CameraController), With>, + mut query: Query<(&mut Transform, &mut CameraController, &mut actor::Actor), With>, ) { let dt = time.delta_seconds(); let mut play_thruster_sound = false; @@ -63,7 +63,7 @@ fn run_camera_controller( focused = window_result.unwrap().focused; } - if let Ok((mut transform, mut controller)) = query.get_single_mut() { + if let Ok((mut transform, mut controller, mut actor)) = query.get_single_mut() { if !controller.initialized { controller.initialized = true; transform.rotation = @@ -97,6 +97,12 @@ fn run_camera_controller( } } + if key_input.pressed(settings.key_stop) { + actor.v = actor.v * 0.99; + if actor.v.length_squared() < 1e-6 { + actor.v = Vec3::ZERO; + } + } let friction = if key_input.pressed(settings.key_stop) { controller.friction.clamp(0.0, 1.0) } else { @@ -116,10 +122,16 @@ fn run_camera_controller( } let forward = *transform.forward(); let right = *transform.right(); - transform.translation += controller.velocity.x * dt * right + actor.v += controller.velocity.x * dt * right + controller.velocity.y * dt * Vec3::Y + controller.velocity.z * dt * forward; + controller.velocity = Vec3::ZERO; + + //transform.translation += controller.velocity.x * dt * right + //+ controller.velocity.y * dt * Vec3::Y + //+ controller.velocity.z * dt * forward; + // Handle mouse input let mut mouse_delta = Vec2::ZERO; for mouse_event in mouse_events.read() {