fix new camera control system to work with vehicles

This commit is contained in:
yuni 2024-03-30 17:05:32 +01:00
parent 3f656924e1
commit e15cf6791f

View file

@ -51,7 +51,7 @@ fn setup_camera(
pub fn sync_camera_to_player(
settings: Res<settings::Settings>,
mut q_camera: Query<&mut Transform, With<Camera>>,
q_playercam: Query<(&actor::Actor, &Transform), (With<actor::PlayerCamera>, Without<actor::PlayerDrivesThis>, Without<Camera>)>,
q_playercam: Query<(&actor::Actor, &Transform), (With<actor::PlayerCamera>, Without<Camera>)>,
) {
if q_camera.is_empty() || q_playercam.is_empty() {
return;
@ -119,13 +119,12 @@ fn apply_input_to_player(
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
mut q_playercam: Query<(
&mut Transform,
&mut actor::Engine,
&mut AngularVelocity,
&mut LinearVelocity,
), (With<actor::PlayerCamera>, Without<actor::PlayerDrivesThis>, Without<Camera>)>,
), (With<actor::PlayerCamera>, Without<Camera>)>,
) {
let dt = time.delta_seconds();
let mut play_thruster_sound = false;
@ -136,7 +135,7 @@ fn apply_input_to_player(
focused = window_result.unwrap().focused;
}
if let Ok((mut player_transform, player_engine, mut angularvelocity, mut v)) = q_playercam.get_single_mut() {
if let Ok((mut player_transform, mut engine, mut angularvelocity, mut v)) = q_playercam.get_single_mut() {
if angularvelocity.length_squared() > 0.0001 {
angularvelocity.x *= 0.98;
@ -182,8 +181,6 @@ fn apply_input_to_player(
// total diagonal acceleration is faster than the forward acceleration alone.
axis_input = axis_input.clamp(Vec3::splat(-1.0), Vec3::splat(1.0));
let mut engine = if let Ok(engine) = q_engine.get_single_mut() { engine } else { player_engine };
// Apply movement update
let forward_factor = engine.current_warmup * (if axis_input.z < 0.0 {
engine.thrust_forward