finally fix player velocity/momentum
This commit is contained in:
parent
50d8d1faee
commit
624582f361
|
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
||||||
use bevy::input::mouse::MouseMotion;
|
use bevy::input::mouse::MouseMotion;
|
||||||
use bevy::window::PrimaryWindow;
|
use bevy::window::PrimaryWindow;
|
||||||
use std::f32::consts::*;
|
use std::f32::consts::*;
|
||||||
use crate::{settings, audio};
|
use crate::{settings, audio, actor};
|
||||||
|
|
||||||
pub struct CameraControllerPlugin;
|
pub struct CameraControllerPlugin;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ impl Default for CameraController {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
initialized: false,
|
initialized: false,
|
||||||
sensitivity: 0.5,
|
sensitivity: 0.5,
|
||||||
move_speed: 1.0,
|
move_speed: 10.0,
|
||||||
friction: 0.1,
|
friction: 0.1,
|
||||||
pitch: 1.0, // pitch=0/yaw=0 -> face sun
|
pitch: 1.0, // pitch=0/yaw=0 -> face sun
|
||||||
yaw: 0.3,
|
yaw: 0.3,
|
||||||
|
@ -52,7 +52,7 @@ fn run_camera_controller(
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
key_input: Res<ButtonInput<KeyCode>>,
|
key_input: Res<ButtonInput<KeyCode>>,
|
||||||
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
|
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
|
||||||
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
mut query: Query<(&mut Transform, &mut CameraController, &mut actor::Actor), With<Camera>>,
|
||||||
) {
|
) {
|
||||||
let dt = time.delta_seconds();
|
let dt = time.delta_seconds();
|
||||||
let mut play_thruster_sound = false;
|
let mut play_thruster_sound = false;
|
||||||
|
@ -63,7 +63,7 @@ fn run_camera_controller(
|
||||||
focused = window_result.unwrap().focused;
|
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 {
|
if !controller.initialized {
|
||||||
controller.initialized = true;
|
controller.initialized = true;
|
||||||
transform.rotation =
|
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) {
|
let friction = if key_input.pressed(settings.key_stop) {
|
||||||
controller.friction.clamp(0.0, 1.0)
|
controller.friction.clamp(0.0, 1.0)
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,10 +122,16 @@ fn run_camera_controller(
|
||||||
}
|
}
|
||||||
let forward = *transform.forward();
|
let forward = *transform.forward();
|
||||||
let right = *transform.right();
|
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.y * dt * Vec3::Y
|
||||||
+ controller.velocity.z * dt * forward;
|
+ 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
|
// Handle mouse input
|
||||||
let mut mouse_delta = Vec2::ZERO;
|
let mut mouse_delta = Vec2::ZERO;
|
||||||
for mouse_event in mouse_events.read() {
|
for mouse_event in mouse_events.read() {
|
||||||
|
|
Loading…
Reference in a new issue