fix npc aiming and shooting
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user