fix flashlight flicker? (cant be sure, since it occurs randomly)
This commit is contained in:
parent
d22a89d022
commit
da58cfc717
17
src/actor.rs
17
src/actor.rs
|
@ -562,14 +562,6 @@ pub fn handle_vehicle_enter_exit(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
|
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
|
||||||
mut ew_achievement: EventWriter<game::AchievementEvent>,
|
mut ew_achievement: EventWriter<game::AchievementEvent>,
|
||||||
mut q_playerflashlight: Query<
|
|
||||||
&mut Transform,
|
|
||||||
(
|
|
||||||
With<PlayersFlashLight>,
|
|
||||||
Without<ActorVehicleBeingEntered>,
|
|
||||||
Without<ActorEnteringVehicle>,
|
|
||||||
),
|
|
||||||
>,
|
|
||||||
mut q_drivers: Query<
|
mut q_drivers: Query<
|
||||||
(Entity, &mut Visibility, Option<&Collider>),
|
(Entity, &mut Visibility, Option<&Collider>),
|
||||||
(
|
(
|
||||||
|
@ -615,10 +607,6 @@ pub fn handle_vehicle_enter_exit(
|
||||||
commands.entity(vehicle).insert(PlayerCamera);
|
commands.entity(vehicle).insert(PlayerCamera);
|
||||||
commands.entity(vehicle).insert(PlayerDrivesThis);
|
commands.entity(vehicle).insert(PlayerDrivesThis);
|
||||||
commands.entity(vehicle).insert(WantsMaxRotation(0.0));
|
commands.entity(vehicle).insert(WantsMaxRotation(0.0));
|
||||||
if let Ok(mut flashlight_trans) = q_playerflashlight.get_single_mut() {
|
|
||||||
flashlight_trans.rotation = Quat::from_rotation_y(0f32);
|
|
||||||
flashlight_trans.translation = Vec3::new(0.0, 0.0, 0.0);
|
|
||||||
}
|
|
||||||
if let Some(vehicle_name) = &event.name {
|
if let Some(vehicle_name) = &event.name {
|
||||||
ew_achievement.send(game::AchievementEvent::RideVehicle(
|
ew_achievement.send(game::AchievementEvent::RideVehicle(
|
||||||
vehicle_name.clone(),
|
vehicle_name.clone(),
|
||||||
|
@ -629,11 +617,6 @@ pub fn handle_vehicle_enter_exit(
|
||||||
if let Some(collider) = &vehicle_component.stored_drivers_collider {
|
if let Some(collider) = &vehicle_component.stored_drivers_collider {
|
||||||
commands.entity(driver).insert(collider.clone());
|
commands.entity(driver).insert(collider.clone());
|
||||||
}
|
}
|
||||||
if let Ok(mut flashlight_trans) = q_playerflashlight.get_single_mut() {
|
|
||||||
flashlight_trans.rotation =
|
|
||||||
Quat::from_rotation_y(180f32.to_radians());
|
|
||||||
flashlight_trans.translation = Vec3::new(0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
commands.entity(driver).remove::<HiddenInsideVehicle>();
|
commands.entity(driver).remove::<HiddenInsideVehicle>();
|
||||||
commands.entity(driver).insert(WantsAcceleration::default());
|
commands.entity(driver).insert(WantsAcceleration::default());
|
||||||
commands.entity(driver).insert(RigidBody::Dynamic);
|
commands.entity(driver).insert(RigidBody::Dynamic);
|
||||||
|
|
|
@ -123,7 +123,11 @@ impl Default for MapCam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_camera(mut commands: Commands, settings: Res<var::Settings>) {
|
pub fn setup_camera(
|
||||||
|
mut commands: Commands,
|
||||||
|
settings: Res<var::Settings>,
|
||||||
|
prefs: Res<var::Preferences>,
|
||||||
|
) {
|
||||||
// Add player
|
// Add player
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Camera3dBundle {
|
Camera3dBundle {
|
||||||
|
@ -152,6 +156,30 @@ pub fn setup_camera(mut commands: Commands, settings: Res<var::Settings>) {
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Add player's flashlight
|
||||||
|
commands.spawn((
|
||||||
|
world::DespawnOnPlayerDeath,
|
||||||
|
actor::PlayersFlashLight,
|
||||||
|
SpotLightBundle {
|
||||||
|
transform: Transform {
|
||||||
|
translation: Vec3::new(0.0, 0.0, 1.0),
|
||||||
|
rotation: Quat::from_rotation_y(180f32.to_radians()),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
spot_light: SpotLight {
|
||||||
|
intensity: actor::FLASHLIGHT_INTENSITY[prefs.flashlight_power],
|
||||||
|
color: Color::WHITE,
|
||||||
|
shadows_enabled: true,
|
||||||
|
inner_angle: PI32 / 8.0 * 0.65,
|
||||||
|
outer_angle: PI32 / 8.0 * 1.2,
|
||||||
|
range: 300000.0,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
visibility: Visibility::Hidden,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
// Add Light from the Sun
|
// Add Light from the Sun
|
||||||
commands.spawn(DirectionalLightBundle {
|
commands.spawn(DirectionalLightBundle {
|
||||||
directional_light: DirectionalLight {
|
directional_light: DirectionalLight {
|
||||||
|
@ -179,6 +207,14 @@ pub fn sync_camera_to_player(
|
||||||
settings: Res<var::Settings>,
|
settings: Res<var::Settings>,
|
||||||
mut q_camera: Query<&mut Transform, (With<Camera>, Without<actor::PlayerCamera>)>,
|
mut q_camera: Query<&mut Transform, (With<Camera>, Without<actor::PlayerCamera>)>,
|
||||||
q_playercam: Query<(&actor::Actor, &Transform), (With<actor::PlayerCamera>, Without<Camera>)>,
|
q_playercam: Query<(&actor::Actor, &Transform), (With<actor::PlayerCamera>, Without<Camera>)>,
|
||||||
|
mut q_flashlight: Query<
|
||||||
|
&mut Transform,
|
||||||
|
(
|
||||||
|
With<actor::PlayersFlashLight>,
|
||||||
|
Without<Camera>,
|
||||||
|
Without<actor::PlayerCamera>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
) {
|
) {
|
||||||
if settings.map_active || q_camera.is_empty() || q_playercam.is_empty() {
|
if settings.map_active || q_camera.is_empty() || q_playercam.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
@ -186,6 +222,15 @@ pub fn sync_camera_to_player(
|
||||||
let mut camera_transform = q_camera.get_single_mut().unwrap();
|
let mut camera_transform = q_camera.get_single_mut().unwrap();
|
||||||
let (actor, player_transform) = q_playercam.get_single().unwrap();
|
let (actor, player_transform) = q_playercam.get_single().unwrap();
|
||||||
|
|
||||||
|
// Flashlight
|
||||||
|
if let Ok(mut flashlight_trans) = q_flashlight.get_single_mut() {
|
||||||
|
let forward = player_transform.translation
|
||||||
|
+ player_transform.rotation * Vec3::new(0.0, 0.0, player_transform.scale.z);
|
||||||
|
flashlight_trans.translation = player_transform.translation;
|
||||||
|
flashlight_trans.look_at(forward, Dir3::Y);
|
||||||
|
flashlight_trans.translation = forward;
|
||||||
|
}
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
let rotation = player_transform.rotation * Quat::from_array([0.0, -1.0, 0.0, 0.0]);
|
let rotation = player_transform.rotation * Quat::from_array([0.0, -1.0, 0.0, 0.0]);
|
||||||
|
|
||||||
|
|
27
src/cmd.rs
27
src/cmd.rs
|
@ -1275,7 +1275,6 @@ fn spawn_entities(
|
||||||
mut achievement_tracker: ResMut<var::AchievementTracker>,
|
mut achievement_tracker: ResMut<var::AchievementTracker>,
|
||||||
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
|
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
|
||||||
settings: Res<var::Settings>,
|
settings: Res<var::Settings>,
|
||||||
prefs: Res<var::Preferences>,
|
|
||||||
) {
|
) {
|
||||||
for state_wrapper in er_spawn.read() {
|
for state_wrapper in er_spawn.read() {
|
||||||
let state = &state_wrapper.0;
|
let state = &state_wrapper.0;
|
||||||
|
@ -1571,32 +1570,6 @@ fn spawn_entities(
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if state.is_player {
|
|
||||||
actor.with_children(|builder| {
|
|
||||||
builder.spawn((
|
|
||||||
world::DespawnOnPlayerDeath,
|
|
||||||
actor::PlayersFlashLight,
|
|
||||||
SpotLightBundle {
|
|
||||||
transform: Transform {
|
|
||||||
translation: Vec3::new(0.0, 0.0, 1.0),
|
|
||||||
rotation: Quat::from_rotation_y(180f32.to_radians()),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
spot_light: SpotLight {
|
|
||||||
intensity: actor::FLASHLIGHT_INTENSITY[prefs.flashlight_power],
|
|
||||||
color: Color::WHITE,
|
|
||||||
shadows_enabled: true,
|
|
||||||
inner_angle: PI32 / 8.0 * 0.65,
|
|
||||||
outer_angle: PI32 / 8.0 * 1.2,
|
|
||||||
range: 300000.0,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
visibility: Visibility::Hidden,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
actor_entity = actor.id();
|
actor_entity = actor.id();
|
||||||
|
|
||||||
for ar_asset_name in &state.ar_models {
|
for ar_asset_name in &state.ar_models {
|
||||||
|
|
Loading…
Reference in a new issue