From 18a799b151dc3bc06daab00f74706b5ab21950df Mon Sep 17 00:00:00 2001 From: extrawurst Date: Mon, 17 Nov 2025 16:10:10 -0300 Subject: [PATCH] fix npc aiming and shooting --- crates/shared/src/ai/mod.rs | 2 +- crates/shared/src/aim/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/shared/src/ai/mod.rs b/crates/shared/src/ai/mod.rs index 8c1b69c..3e1188e 100644 --- a/crates/shared/src/ai/mod.rs +++ b/crates/shared/src/ai/mod.rs @@ -127,7 +127,7 @@ fn rotate(agent: Query<(Entity, &Engage)>, mut transform: Query<&mut Transform>) }; // Get the direction vector from the current position to the target - let direction = (target_pos - agent_transform.translation).normalize(); + let direction = (agent_transform.translation - target_pos).normalize(); // Project the direction onto the XZ plane by zeroing out the Y component let xz_direction = Vec3::new(direction.x, 0.0, direction.z).normalize(); diff --git a/crates/shared/src/aim/mod.rs b/crates/shared/src/aim/mod.rs index 3275a60..56991fc 100644 --- a/crates/shared/src/aim/mod.rs +++ b/crates/shared/src/aim/mod.rs @@ -146,7 +146,7 @@ fn update_npc_aim( let mut target_distance = f32::MAX; for (e, t) in potential_targets.iter() { - let delta = pos - t.translation; + let delta = t.translation - pos; let distance = delta.length();