This commit is contained in:
2026-03-22 11:02:36 +00:00
parent 749913a028
commit b2dc0cb864
3 changed files with 18 additions and 22 deletions
+7 -2
View File
@@ -3,7 +3,7 @@
//! This module contains the logic that was previously in the wandering
//! system. Now it's called by the task executor when Task::Idle is active.
use crate::constants::ITILE_SIZE;
use crate::constants::{ITILE_SIZE, TILE_SIZE};
use crate::entities::shared_components::Ambulatory;
use crate::entities::tasks::components::Task;
use crate::world::tiles::tilemap::TileMap;
@@ -34,8 +34,13 @@ pub(super) fn execute_idle(
// Track if target actually changed this tick
let mut target_changed = false;
// Use distance threshold for arrival check - equality never triggers due to float truncation
let dist_sq = (transform.translation.x - target.x as f32).powi(2)
+ (transform.translation.y - target.y as f32).powi(2);
let arrived = dist_sq < (TILE_SIZE * 1.5) * (TILE_SIZE * 1.5);
// If reached target or target is no longer standable, pick new target
if entity_pos == *target || !tilemap.is_standable(*target) {
if arrived || !tilemap.is_standable(*target) {
if let Some(new_target) = pick_wander_target(origin, *wander_radius, tilemap, rng) {
*target = new_target;
target_changed = true;