Fix update_wandering_targets target validation logic
- Restored original target selection logic that validates is_standable_tile - Fixed target position z-level checking (check floor tile then standable) - Re-added check for completed paths (path_index >= path.len) - This was the cause of 50,297 failed paths - entities targeting invalid positions
This commit is contained in:
+2380
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
sample,path_duration_us,path_length,nodes_expanded,success
|
||||
0,484,142,142,true
|
||||
1,449,148,148,true
|
||||
2,408,124,124,true
|
||||
3,742,116,116,true
|
||||
4,296,94,94,true
|
||||
5,563,126,126,true
|
||||
6,349,128,128,true
|
||||
7,422,120,120,true
|
||||
8,195,0,105,true
|
||||
9,191,0,111,true
|
||||
10,419,146,146,true
|
||||
11,356,119,119,true
|
||||
12,34,4,4,true
|
||||
13,414,133,133,true
|
||||
14,216,0,117,true
|
||||
15,16,4,4,true
|
||||
16,664,119,119,true
|
||||
17,528,119,119,true
|
||||
18,295,116,116,true
|
||||
19,22,2,2,true
|
||||
# Summary
|
||||
# avg_duration_us,353
|
||||
# total_paths,20
|
||||
# failed_paths,50297
|
||||
|
@@ -200,15 +200,11 @@ pub fn update_wandering_targets(
|
||||
return;
|
||||
};
|
||||
|
||||
query.iter_mut().for_each(|(mut ambulatory, transform)| {
|
||||
if ambulatory.target.is_none() {
|
||||
let center = transform.translation;
|
||||
let center_chunk = IVec2::new(
|
||||
(center.x / (CHUNK_SIZE as f32 * TILE_SIZE)).floor() as i32,
|
||||
(center.y / (CHUNK_SIZE as f32 * TILE_SIZE)).floor() as i32,
|
||||
);
|
||||
|
||||
if chunk_map.loaded_chunks.contains_key(¢er_chunk) {
|
||||
for (mut ambulatory, _) in query.iter_mut() {
|
||||
if ambulatory.target.is_none()
|
||||
|| (ambulatory.current_path.is_some()
|
||||
&& ambulatory.path_index >= ambulatory.current_path.as_ref().unwrap().len())
|
||||
{
|
||||
let loaded_chunks: Vec<&IVec2> = chunk_map.loaded_chunks.keys().collect();
|
||||
if !loaded_chunks.is_empty() {
|
||||
let random_index = rng.random_range(0..loaded_chunks.len());
|
||||
@@ -220,8 +216,12 @@ pub fn update_wandering_targets(
|
||||
let target_y = chunk_y + rng.random_range(0..CHUNK_SIZE);
|
||||
|
||||
for z in -3..=4 {
|
||||
let target_pos = IVec3::new(target_x, target_y, z) * ITILE_SIZE;
|
||||
if tilemap.floor_tiles.contains_key(&target_pos) {
|
||||
let mut target_pos = IVec3::new(target_x, target_y, z) * ITILE_SIZE;
|
||||
if tilemap.floor_tiles.get(&target_pos).is_some() {
|
||||
target_pos.z += ITILE_SIZE;
|
||||
if tilemap.floor_tiles.get(&target_pos).is_some()
|
||||
&& is_standable_tile(&tilemap, target_pos)
|
||||
{
|
||||
ambulatory.target = Some(Vec3::new(
|
||||
target_pos.x as f32,
|
||||
target_pos.y as f32,
|
||||
@@ -236,7 +236,7 @@ pub fn update_wandering_targets(
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn movement(mut query: Query<(&mut Ambulatory, &mut Transform)>, tilemap: Res<TileMap>) {
|
||||
|
||||
Reference in New Issue
Block a user