Only check collisions with map when pathfinding.

This commit is contained in:
Nolan Darilek 2022-05-07 04:50:17 -05:00
parent 9307852eda
commit 623b731765

View File

@ -108,7 +108,7 @@ fn calculate_path<D: 'static + Clone + Default + Send + Sync>(
mut commands: Commands, mut commands: Commands,
pool: Res<AsyncComputeTaskPool>, pool: Res<AsyncComputeTaskPool>,
rapier_context: Res<RapierContext>, rapier_context: Res<RapierContext>,
obstructions: Query<&MapObstruction>, obstructions: Query<&RapierColliderHandle, With<MapObstruction>>,
query: Query< query: Query<
( (
Entity, Entity,
@ -138,7 +138,24 @@ fn calculate_path<D: 'static + Clone + Default + Send + Sync>(
let query_pipeline = rapier_context.query_pipeline.clone(); let query_pipeline = rapier_context.query_pipeline.clone();
let map_clone = map.clone(); let map_clone = map.clone();
let handle_clone = *handle; let handle_clone = *handle;
let collider_set = rapier_context.colliders.clone(); let mut collider_set = rapier_context.colliders.clone();
let obstructions = obstructions
.iter()
.map(|v| v.0)
.collect::<Vec<ColliderHandle>>();
let mut to_remove = vec![];
for handle in collider_set.iter() {
if !obstructions.contains(&handle.0) {
to_remove.push(handle.0);
}
}
if !to_remove.is_empty() {
let mut islands = rapier_context.islands.clone();
let mut bodies = rapier_context.bodies.clone();
for handle in to_remove {
collider_set.remove(handle, &mut islands, &mut bodies, false);
}
}
let shape_clone = (*shape).clone(); let shape_clone = (*shape).clone();
let task = pool.spawn(async move { let task = pool.spawn(async move {
find_path_for_shape( find_path_for_shape(