trying to fix player "teleportation" on vehicle exiting...
This commit is contained in:
parent
962f73f522
commit
ce8f4666c5
31
src/actor.rs
31
src/actor.rs
|
@ -285,6 +285,7 @@ pub fn handle_input(
|
||||||
is_entering: false,
|
is_entering: false,
|
||||||
is_player: true,
|
is_player: true,
|
||||||
});
|
});
|
||||||
|
commands.entity(player_entity).insert(RigidBody::Dynamic);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,43 +296,43 @@ 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 Visibility, &mut Transform), (Without<ActorVehicleBeingEntered>, With<ActorEnteringVehicle>)>,
|
mut q_drivers: Query<(Entity, &mut Visibility, &mut Transform, &mut LinearVelocity, &mut AngularVelocity), (Without<ActorVehicleBeingEntered>, With<ActorEnteringVehicle>)>,
|
||||||
mut q_vehicles: Query<(Entity, &mut Visibility, &mut Transform), (With<ActorVehicleBeingEntered>, Without<ActorEnteringVehicle>)>,
|
mut q_vehicles: Query<(Entity, &mut Visibility, &mut Transform, &LinearVelocity, &AngularVelocity), (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_vis, mut driver_trans) in q_drivers.iter_mut() {
|
for (driver, mut driver_vis, mut driver_trans, mut driver_linv, mut driver_angv) in q_drivers.iter_mut() {
|
||||||
if driver == event.driver {
|
if driver == event.driver {
|
||||||
for (vehicle, mut vehicle_vis, vehicle_trans) in q_vehicles.iter_mut() {
|
for (vehicle, mut vehicle_vis, vehicle_trans, vehicle_linv, vehicle_angv) 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;
|
commands.entity(driver).remove::<RigidBody>();
|
||||||
if event.is_player {
|
if event.is_player {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
||||||
//*vehicle_vis = Visibility::Hidden;
|
|
||||||
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_linv = vehicle_linv.clone();
|
||||||
|
*driver_angv = vehicle_angv.clone();
|
||||||
|
driver_trans.translation = vehicle_trans.translation;
|
||||||
|
driver_trans.rotation = vehicle_trans.rotation;
|
||||||
|
// NOTE: I would rather have the following line here,
|
||||||
|
// but then, for some reason, changing driver translation
|
||||||
|
// does not work. For now, you must manually insert the RigidBody
|
||||||
|
// component from the place that adds this event.
|
||||||
|
//commands.entity(driver).insert(RigidBody::Dynamic);
|
||||||
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;
|
|
||||||
// TODO: set actor momentum to vehicle momentum (linear/angular)
|
|
||||||
commands.entity(driver).insert(RigidBody::Dynamic);
|
|
||||||
|
|
||||||
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>();
|
||||||
|
*vehicle_vis = Visibility::Inherited;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
*driver_trans = vehicle_trans.clone();
|
|
||||||
}
|
|
||||||
driver_trans.translation = vehicle_trans.translation.clone();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,7 @@ use bevy::window::PrimaryWindow;
|
||||||
use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
|
use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
|
||||||
use bevy::core_pipeline::tonemapping::Tonemapping;
|
use bevy::core_pipeline::tonemapping::Tonemapping;
|
||||||
use bevy_xpbd_3d::prelude::*;
|
use bevy_xpbd_3d::prelude::*;
|
||||||
use bevy_xpbd_3d::PhysicsSchedule;
|
use bevy_xpbd_3d::{PhysicsSchedule, PhysicsStepSet};
|
||||||
use bevy_xpbd_3d::PhysicsStepSet;
|
|
||||||
use std::f32::consts::*;
|
use std::f32::consts::*;
|
||||||
use crate::{settings, audio, actor};
|
use crate::{settings, audio, actor};
|
||||||
|
|
||||||
|
@ -92,8 +91,10 @@ pub fn handle_input(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn manage_player_actor(
|
fn manage_player_actor(
|
||||||
|
mut commands: Commands,
|
||||||
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 {
|
||||||
|
@ -103,6 +104,9 @@ 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)]
|
||||||
|
|
|
@ -112,7 +112,7 @@ actor 10 -30 20 MeteorAceGT
|
||||||
vehicle yes
|
vehicle yes
|
||||||
thrust 70 13.7 9.4 0.5 20
|
thrust 70 13.7 9.4 0.5 20
|
||||||
engine ion
|
engine ion
|
||||||
collider sphere 2
|
collider sphere 1.5
|
||||||
camdistance 50
|
camdistance 50
|
||||||
mass 500
|
mass 500
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue