fix position/rotation after exiting vehicle

This commit is contained in:
yuni 2024-04-03 12:26:56 +02:00
parent 2f060a3250
commit 8531a9b8c1

View file

@ -5,7 +5,7 @@ use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
use bevy::core_pipeline::tonemapping::Tonemapping;
use bevy::pbr::CascadeShadowConfigBuilder;
use bevy::transform::TransformSystem;
use bevy::math::DVec3;
use bevy::math::{DVec3, DQuat};
use bevy_xpbd_3d::prelude::*;
use std::f32::consts::PI;
use crate::{settings, audio, actor};
@ -113,8 +113,8 @@ pub fn handle_input(
fn manage_player_actor(
settings: Res<settings::Settings>,
mut q_playercam: Query<&mut Visibility, With<actor::PlayerCamera>>,
mut q_hiddenplayer: Query<(&mut Visibility, &mut Transform, &mut LinearVelocity, &mut AngularVelocity), (With<actor::Player>, Without<actor::PlayerCamera>)>,
q_ride: Query<(&Transform, &LinearVelocity, &AngularVelocity), (With<actor::PlayerDrivesThis>, Without<actor::Player>)>,
mut q_hiddenplayer: Query<(&mut Visibility, &mut Position, &mut Rotation, &mut LinearVelocity, &mut AngularVelocity), (With<actor::Player>, Without<actor::PlayerCamera>)>,
q_ride: Query<(&Transform, &Position, &Rotation, &LinearVelocity, &AngularVelocity), (With<actor::PlayerDrivesThis>, Without<actor::Player>)>,
) {
for mut vis in &mut q_playercam {
if settings.third_person {
@ -124,11 +124,11 @@ fn manage_player_actor(
*vis = Visibility::Hidden;
}
}
for (mut vis, mut trans, mut v, mut angv) in &mut q_hiddenplayer {
for (mut vis, mut pos, mut rot, mut v, mut angv) in &mut q_hiddenplayer {
*vis = Visibility::Hidden;
if let Ok((ride_trans, ride_v, ride_angv)) = q_ride.get_single() {
trans.translation = ride_trans.translation + Vec3::new(0.0, 0.0, 10.0);
trans.rotation = ride_trans.rotation;
if let Ok((ride_trans, ride_pos, ride_rot, ride_v, ride_angv)) = q_ride.get_single() {
pos.0 = ride_pos.0 + DVec3::from(ride_trans.rotation * Vec3::new(0.0, 0.0, 10.0));
rot.0 = ride_rot.0 * DQuat::from_array([-1.0, 0.0, 0.0, 0.0]);
*v = ride_v.clone();
*angv = ride_angv.clone();
}