stop physics simulation of original model when entering vehicle
This commit is contained in:
parent
b590c4de44
commit
962f73f522
21
src/actor.rs
21
src/actor.rs
|
@ -295,37 +295,35 @@ pub fn handle_input(
|
||||||
pub fn handle_vehicle_enter_exit(
|
pub fn handle_vehicle_enter_exit(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
|
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
|
||||||
mut q_drivers: Query<(Entity, &mut Actor, &mut Visibility, &mut Transform), (Without<ActorVehicleBeingEntered>, With<ActorEnteringVehicle>)>,
|
mut q_drivers: Query<(Entity, &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_vehicles: Query<(Entity, &mut Visibility, &mut Transform), (With<ActorVehicleBeingEntered>, Without<ActorEnteringVehicle>)>,
|
||||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
) {
|
) {
|
||||||
for event in er_vehicle.read() {
|
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 {
|
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 vehicle == event.vehicle {
|
||||||
if event.is_entering {
|
if event.is_entering {
|
||||||
// Entering Vehicle
|
// Entering Vehicle
|
||||||
*driver_vis = Visibility::Hidden;
|
*driver_vis = Visibility::Hidden;
|
||||||
if event.is_player {
|
if event.is_player {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
||||||
//player_actor.inside_entity = entity.index();
|
//*vehicle_vis = Visibility::Hidden;
|
||||||
*vehicle_vis = Visibility::Hidden;
|
|
||||||
driver_actor.v = vehicle_actor.v;
|
|
||||||
commands.entity(driver).remove::<PlayerCamera>();
|
commands.entity(driver).remove::<PlayerCamera>();
|
||||||
commands.entity(vehicle).insert(PlayerCamera);
|
commands.entity(vehicle).insert(PlayerCamera);
|
||||||
commands.entity(vehicle).insert(PlayerDrivesThis);
|
commands.entity(vehicle).insert(PlayerDrivesThis);
|
||||||
|
commands.entity(driver).remove::<RigidBody>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Exiting Vehicle
|
// Exiting Vehicle
|
||||||
*driver_vis = Visibility::Inherited;
|
|
||||||
if event.is_player {
|
if event.is_player {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||||
*vehicle_vis = Visibility::Inherited;
|
*vehicle_vis = Visibility::Inherited;
|
||||||
vehicle_actor.v = driver_actor.v;
|
// TODO: set actor momentum to vehicle momentum (linear/angular)
|
||||||
vehicle_actor.angular_momentum = driver_actor.angular_momentum;
|
commands.entity(driver).insert(RigidBody::Dynamic);
|
||||||
*vehicle_trans = driver_trans.clone();
|
|
||||||
commands.entity(vehicle).remove::<PlayerCamera>();
|
commands.entity(vehicle).remove::<PlayerCamera>();
|
||||||
commands.entity(driver).insert(PlayerCamera);
|
commands.entity(driver).insert(PlayerCamera);
|
||||||
commands.entity(vehicle).remove::<PlayerDrivesThis>();
|
commands.entity(vehicle).remove::<PlayerDrivesThis>();
|
||||||
|
@ -333,6 +331,7 @@ pub fn handle_vehicle_enter_exit(
|
||||||
else {
|
else {
|
||||||
*driver_trans = vehicle_trans.clone();
|
*driver_trans = vehicle_trans.clone();
|
||||||
}
|
}
|
||||||
|
driver_trans.translation = vehicle_trans.translation.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,6 @@ pub fn handle_input(
|
||||||
fn manage_player_actor(
|
fn manage_player_actor(
|
||||||
settings: Res<settings::Settings>,
|
settings: Res<settings::Settings>,
|
||||||
mut q_playercam: Query<&mut Visibility, With<actor::PlayerCamera>>,
|
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 {
|
for mut vis in &mut q_playercam {
|
||||||
if settings.third_person {
|
if settings.third_person {
|
||||||
|
@ -104,9 +103,6 @@ fn manage_player_actor(
|
||||||
*vis = Visibility::Hidden;
|
*vis = Visibility::Hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for mut vis in &mut q_hiddenplayer {
|
|
||||||
*vis = Visibility::Hidden;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
Loading…
Reference in a new issue