From 623b7317656bfb8f8e7a36ddc382aaf18d33b421 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sat, 7 May 2022 04:50:17 -0500 Subject: [PATCH] Only check collisions with map when pathfinding. --- src/pathfinding.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/pathfinding.rs b/src/pathfinding.rs index 5056ccc..b36722c 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -108,7 +108,7 @@ fn calculate_path( mut commands: Commands, pool: Res, rapier_context: Res, - obstructions: Query<&MapObstruction>, + obstructions: Query<&RapierColliderHandle, With>, query: Query< ( Entity, @@ -138,7 +138,24 @@ fn calculate_path( let query_pipeline = rapier_context.query_pipeline.clone(); let map_clone = map.clone(); 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::>(); + 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 task = pool.spawn(async move { find_path_for_shape(