smoother handling of vehicle entrance/exits, also fixes adrenaline
This commit is contained in:
parent
97640c383c
commit
9975d8b2bf
62
src/actor.rs
62
src/actor.rs
|
@ -141,7 +141,12 @@ impl Default for LifeForm { fn default() -> Self { Self {
|
|||
}}}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Vehicle;
|
||||
pub struct Vehicle {
|
||||
stored_drivers_collider: Option<Collider>,
|
||||
}
|
||||
impl Default for Vehicle { fn default() -> Self { Self {
|
||||
stored_drivers_collider: None,
|
||||
}}}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum EngineType {
|
||||
|
@ -194,17 +199,17 @@ const SUIT_SIMPLE: Suit = Suit {
|
|||
|
||||
pub fn update_physics_lifeforms(
|
||||
time: Res<Time>,
|
||||
mut query: Query<(&mut LifeForm, &mut Suit, &Actor)>,
|
||||
mut query: Query<(&mut LifeForm, &mut Suit, &LinearVelocity)>,
|
||||
) {
|
||||
let d = time.delta_seconds();
|
||||
for (mut lifeform, mut suit, actor) in query.iter_mut() {
|
||||
for (mut lifeform, mut suit, velocity) in query.iter_mut() {
|
||||
if lifeform.adrenaline_jolt.abs() > 1e-3 {
|
||||
lifeform.adrenaline_jolt *= 0.99;
|
||||
}
|
||||
else {
|
||||
lifeform.adrenaline_jolt = 0.0
|
||||
}
|
||||
let speed = actor.v.length();
|
||||
let speed = velocity.length();
|
||||
if speed > 1000.0 {
|
||||
lifeform.adrenaline += 0.001;
|
||||
}
|
||||
|
@ -286,7 +291,6 @@ pub fn handle_input(
|
|||
is_entering: false,
|
||||
is_player: true,
|
||||
});
|
||||
commands.entity(player_entity).insert(RigidBody::Dynamic);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -297,44 +301,42 @@ pub fn handle_input(
|
|||
pub fn handle_vehicle_enter_exit(
|
||||
mut commands: Commands,
|
||||
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
|
||||
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, &LinearVelocity, &AngularVelocity), (With<ActorVehicleBeingEntered>, Without<ActorEnteringVehicle>)>,
|
||||
mut q_drivers: Query<(Entity, &mut Visibility, Option<&Collider>), (Without<ActorVehicleBeingEntered>, With<ActorEnteringVehicle>)>,
|
||||
mut q_vehicles: Query<(Entity, &mut Vehicle, &mut Visibility), (With<ActorVehicleBeingEntered>, Without<ActorEnteringVehicle>)>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
) {
|
||||
for event in er_vehicle.read() {
|
||||
for (driver, mut driver_vis, mut driver_trans, mut driver_linv, mut driver_angv) in q_drivers.iter_mut() {
|
||||
for (driver, mut driver_vis, driver_collider) in q_drivers.iter_mut() {
|
||||
if driver == event.driver {
|
||||
for (vehicle, mut vehicle_vis, vehicle_trans, vehicle_linv, vehicle_angv) in q_vehicles.iter_mut() {
|
||||
for (vehicle, mut vehicle_component, mut vehicle_vis) in q_vehicles.iter_mut() {
|
||||
if !event.is_player {
|
||||
continue;
|
||||
}
|
||||
if vehicle == event.vehicle {
|
||||
if event.is_entering {
|
||||
// Entering Vehicle
|
||||
if let Some(collider) = driver_collider {
|
||||
vehicle_component.stored_drivers_collider = Some(collider.clone());
|
||||
}
|
||||
commands.entity(driver).remove::<RigidBody>();
|
||||
*driver_vis = Visibility::Hidden; //seems to have no effect...
|
||||
if event.is_player {
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
||||
commands.entity(driver).remove::<PlayerCamera>();
|
||||
commands.entity(vehicle).insert(PlayerCamera);
|
||||
commands.entity(vehicle).insert(PlayerDrivesThis);
|
||||
}
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
||||
commands.entity(driver).remove::<PlayerCamera>();
|
||||
commands.entity(driver).remove::<Collider>();
|
||||
commands.entity(vehicle).insert(PlayerCamera);
|
||||
commands.entity(vehicle).insert(PlayerDrivesThis);
|
||||
}
|
||||
else {
|
||||
// Exiting Vehicle
|
||||
*driver_linv = vehicle_linv.clone();
|
||||
*driver_angv = vehicle_angv.clone();
|
||||
driver_trans.translation = vehicle_trans.translation + Vec3::new(0.0, 0.0, 10.0);
|
||||
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 {
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||
commands.entity(vehicle).remove::<PlayerCamera>();
|
||||
commands.entity(driver).insert(PlayerCamera);
|
||||
commands.entity(vehicle).remove::<PlayerDrivesThis>();
|
||||
*vehicle_vis = Visibility::Inherited;
|
||||
if let Some(collider) = &vehicle_component.stored_drivers_collider {
|
||||
commands.entity(driver).insert(collider.clone());
|
||||
}
|
||||
commands.entity(driver).insert(RigidBody::Dynamic);
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||
commands.entity(vehicle).remove::<PlayerCamera>();
|
||||
commands.entity(driver).insert(PlayerCamera);
|
||||
commands.entity(vehicle).remove::<PlayerDrivesThis>();
|
||||
*vehicle_vis = Visibility::Inherited;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,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, (With<actor::Player>, Without<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>)>,
|
||||
) {
|
||||
for mut vis in &mut q_playercam {
|
||||
if settings.third_person {
|
||||
|
@ -107,8 +108,14 @@ fn manage_player_actor(
|
|||
*vis = Visibility::Hidden;
|
||||
}
|
||||
}
|
||||
for mut vis in &mut q_hiddenplayer {
|
||||
for (mut vis, mut trans, 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;
|
||||
*v = ride_v.clone();
|
||||
*angv = ride_angv.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -369,7 +369,7 @@ impl ParserState {
|
|||
});
|
||||
}
|
||||
if self.is_vehicle {
|
||||
actor.insert(actor::Vehicle);
|
||||
actor.insert(actor::Vehicle::default());
|
||||
}
|
||||
if self.is_vehicle || self.is_suited {
|
||||
actor.insert(actor::Engine {
|
||||
|
|
Loading…
Reference in a new issue