feat(pathfinding): implement Phase 3 reactive pathing

- Add validation_cooldown field to Ambulatory component
- Implement validate_next_steps to check walkability of next 3 path nodes
- Integrate validation into movement system (every 10 frames)
- Trigger re-path when validation fails (path blocked or invalid)
- Entities now detect and recover from invalid paths automatically
This commit is contained in:
2026-03-18 21:33:38 +00:00
parent a6f6e7cb9d
commit 49f91de0c9
5 changed files with 40 additions and 0 deletions
@@ -502,6 +502,17 @@ pub fn movement(mut query: Query<(&mut Ambulatory, &mut Transform)>, tilemap: Re
return;
}
if ambulatory.validation_cooldown > 0 {
ambulatory.validation_cooldown -= 1;
} else if let Some(path) = &ambulatory.current_path {
if !validate_next_steps(&tilemap, path, ambulatory.path_index, 3) {
ambulatory.current_path = None;
ambulatory.validation_cooldown = 10;
return;
}
ambulatory.validation_cooldown = 10;
}
if ambulatory.walk_speed > 0. {
if ambulatory.step_recovery <= ambulatory.walk_speed as u32 {
ambulatory.step_recovery += 1;
@@ -534,6 +545,17 @@ pub fn movement(mut query: Query<(&mut Ambulatory, &mut Transform)>, tilemap: Re
});
}
fn validate_next_steps(tilemap: &TileMap, path: &[Vec3], start_index: usize, steps: usize) -> bool {
let end = (start_index + steps).min(path.len());
for i in start_index..end {
let pos = path[i].as_ivec3();
if !is_standable_tile(tilemap, pos) {
return false;
}
}
true
}
fn is_standable_tile(tilemap: &TileMap, pos: IVec3) -> bool {
let can_stand_in_tile = tilemap
.floor_tiles