Various visibility fixes.

This commit is contained in:
Nolan Darilek 2024-08-25 17:59:57 -05:00
parent 2c378d65a2
commit 8eb050d10a

View File

@ -146,7 +146,30 @@ impl Viewshed {
};
if let Some((opacity, coord_entities)) = result {
for e in &coord_entities {
new_visible_entities.insert(*e);
let mut should_insert = true;
if coord_entities.len() > 1 {
let start = start.translation().truncate();
let dest = Vec2::new(coord.x as f32, coord.y as f32);
let dir = dest - start;
rapier_context.intersections_with_ray(
start,
dir,
1.,
true,
QueryFilter::new()
.exclude_sensors()
.exclude_collider(*viewer_entity)
.exclude_collider(*e)
.predicate(&|e| visible_query.contains(e)),
|_, _| {
should_insert = false;
false
},
);
}
if should_insert {
new_visible_entities.insert(*e);
}
}
opacity
} else {
@ -187,7 +210,7 @@ impl Viewshed {
}
}
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut, Reflect)]
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut, Eq, PartialEq, Reflect)]
#[reflect(Component)]
pub struct Visible(pub u8);
@ -437,6 +460,9 @@ impl<MapData: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlug
update_revealed_tiles::<MapData>,
),
)
.add_systems(FixedPostUpdate, (log_visible, viewshed_removed, remove_visible));
.add_systems(
FixedPostUpdate,
(log_visible, viewshed_removed, remove_visible),
);
}
}