stop physics simulation of original model when entering vehicle

This commit is contained in:
yuni 2024-03-30 18:05:22 +01:00
parent b590c4de44
commit 962f73f522
2 changed files with 10 additions and 15 deletions

View file

@ -295,37 +295,35 @@ pub fn handle_input(
pub fn handle_vehicle_enter_exit(
mut commands: Commands,
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
mut q_drivers: Query<(Entity, &mut Actor, &mut Visibility, &mut Transform), (Without<ActorVehicleBeingEntered>, With<ActorEnteringVehicle>)>,
mut q_vehicles: Query<(Entity, &mut Actor, &mut Visibility, &mut Transform), (With<ActorVehicleBeingEntered>, Without<ActorEnteringVehicle>)>,
mut q_drivers: Query<(Entity, &mut Visibility, &mut Transform), (Without<ActorVehicleBeingEntered>, With<ActorEnteringVehicle>)>,
mut q_vehicles: Query<(Entity, &mut Visibility, &mut Transform), (With<ActorVehicleBeingEntered>, Without<ActorEnteringVehicle>)>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
) {
for event in er_vehicle.read() {
for (driver, mut driver_actor, mut driver_vis, mut driver_trans) in q_drivers.iter_mut() {
for (driver, mut driver_vis, mut driver_trans) in q_drivers.iter_mut() {
if driver == event.driver {
for (vehicle, mut vehicle_actor, mut vehicle_vis, mut vehicle_trans) in q_vehicles.iter_mut() {
for (vehicle, mut vehicle_vis, vehicle_trans) in q_vehicles.iter_mut() {
if vehicle == event.vehicle {
if event.is_entering {
// Entering Vehicle
*driver_vis = Visibility::Hidden;
if event.is_player {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
//player_actor.inside_entity = entity.index();
*vehicle_vis = Visibility::Hidden;
driver_actor.v = vehicle_actor.v;
//*vehicle_vis = Visibility::Hidden;
commands.entity(driver).remove::<PlayerCamera>();
commands.entity(vehicle).insert(PlayerCamera);
commands.entity(vehicle).insert(PlayerDrivesThis);
commands.entity(driver).remove::<RigidBody>();
}
}
else {
// Exiting Vehicle
*driver_vis = Visibility::Inherited;
if event.is_player {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
*vehicle_vis = Visibility::Inherited;
vehicle_actor.v = driver_actor.v;
vehicle_actor.angular_momentum = driver_actor.angular_momentum;
*vehicle_trans = driver_trans.clone();
// TODO: set actor momentum to vehicle momentum (linear/angular)
commands.entity(driver).insert(RigidBody::Dynamic);
commands.entity(vehicle).remove::<PlayerCamera>();
commands.entity(driver).insert(PlayerCamera);
commands.entity(vehicle).remove::<PlayerDrivesThis>();
@ -333,6 +331,7 @@ pub fn handle_vehicle_enter_exit(
else {
*driver_trans = vehicle_trans.clone();
}
driver_trans.translation = vehicle_trans.translation.clone();
}
}
}

View file

@ -94,7 +94,6 @@ 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, (With<actor::Player>, Without<actor::PlayerCamera>)>,
) {
for mut vis in &mut q_playercam {
if settings.third_person {
@ -104,9 +103,6 @@ fn manage_player_actor(
*vis = Visibility::Hidden;
}
}
for mut vis in &mut q_hiddenplayer {
*vis = Visibility::Hidden;
}
}
#[allow(clippy::too_many_arguments)]