Fix minor bugs with NPCs

This commit is contained in:
Joshua Barretto 2020-04-23 13:29:22 +01:00
parent 1983fd8ec1
commit a7b5d6b270
3 changed files with 9 additions and 11 deletions

View File

@ -27,7 +27,7 @@ impl EntityInfo {
alignment: Alignment::Wild,
body: Body::Humanoid(humanoid::Body::random()),
name: None,
main_tool: None,
main_tool: Some(Item::empty()),
}
}

View File

@ -74,8 +74,8 @@ impl Route {
if vol.get(next).map(|b| b.is_solid()).unwrap_or(false) {
None
} else {
let next_tgt = next.map(|e| e as f32) + 0.5;
if ((pos - next_tgt) * Vec3::new(1.0, 1.0, 0.3)).magnitude_squared()
let next_tgt = next.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0);
if ((pos - (next_tgt + Vec3::unit_z() * 0.5)) * Vec3::new(1.0, 1.0, 0.3)).magnitude_squared()
< (traversal_tolerance * 2.0).powf(2.0)
{
self.next_idx += 1;

View File

@ -113,7 +113,8 @@ impl<'a> System<'a> for Sys {
const SIGHT_DIST: f32 = 128.0;
const MIN_ATTACK_DIST: f32 = 3.25;
let traversal_tolerance = scales.get(entity).map(|s| s.0).unwrap_or(1.0);
let scale = scales.get(entity).map(|s| s.0).unwrap_or(1.0);
let traversal_tolerance = scale;
let mut do_idle = false;
let mut choose_target = false;
@ -248,19 +249,16 @@ impl<'a> System<'a> for Sys {
}
let dist_sqrd = pos.0.distance_squared(tgt_pos.0);
if dist_sqrd < MIN_ATTACK_DIST.powf(2.0) {
if dist_sqrd < (MIN_ATTACK_DIST * scale).powf(2.0) {
// Close-range attack
inputs.move_dir = Vec2::from(tgt_pos.0 - pos.0)
.try_normalized()
.unwrap_or(Vec2::unit_y())
* 0.7;
if let Tactic::Melee = tactic {
inputs.primary.set_state(true);
} else if let Tactic::Staff = tactic {
inputs.primary.set_state(true);
} else {
inputs.roll.set_state(true);
match tactic {
Tactic::Melee | Tactic::Staff => inputs.primary.set_state(true),
Tactic::RangedPowerup => inputs.roll.set_state(true),
}
} else if dist_sqrd < MAX_CHASE_DIST.powf(2.0)
|| (dist_sqrd < SIGHT_DIST.powf(2.0)