Various bug fixes

This commit is contained in:
Joshua Barretto 2020-01-25 21:43:02 +00:00
parent 8c7e96e313
commit 7437c18b99
3 changed files with 23 additions and 19 deletions

View File

@ -110,7 +110,7 @@ impl Chaser {
{
let pos_to_tgt = pos.distance(tgt);
if pos_to_tgt < min_dist {
if ((pos - tgt) * Vec3::new(1.0, 1.0, 0.3)).magnitude_squared() < min_dist.powf(2.0) {
return None;
}

View File

@ -74,7 +74,7 @@ impl<'a> System<'a> for Sys {
const AVG_FOLLOW_DIST: f32 = 6.0;
const MAX_FOLLOW_DIST: f32 = 12.0;
const MAX_CHASE_DIST: f32 = 24.0;
const SIGHT_DIST: f32 = 20.0;
const SIGHT_DIST: f32 = 30.0;
const MIN_ATTACK_DIST: f32 = 3.25;
const PATROL_DIST: f32 = 32.0;
@ -83,9 +83,9 @@ impl<'a> System<'a> for Sys {
match &mut agent.activity {
Activity::Idle(wander_pos, chaser) => {
if let Some(patrol_origin) = agent.patrol_origin {
if thread_rng().gen::<f32>() < 0.002 {
if thread_rng().gen::<f32>() < 0.005 {
*wander_pos =
if thread_rng().gen::<f32>() < 0.5 {
if thread_rng().gen::<f32>() < 0.7 {
Some(patrol_origin.map(|e| {
e + thread_rng().gen_range(-1.0, 1.0) * PATROL_DIST
}))
@ -157,7 +157,7 @@ impl<'a> System<'a> for Sys {
inputs.look_dir = tgt_pos.0 - pos.0;
inputs.move_dir = Vec2::from(tgt_pos.0 - pos.0)
.try_normalized()
.unwrap_or(Vec2::zero())
.unwrap_or(Vec2::unit_y())
* 0.01;
inputs.primary.set_state(true);
} else if dist < MAX_CHASE_DIST {

View File

@ -1458,21 +1458,25 @@ impl WorldSim {
let mut pos = Vec2::new(i as i32, j as i32);
// Slide the waypoints down hills
loop {
for _ in 0..32 {
let last_pos = pos;
let alt = this.get(pos + Vec2::new(1, 0))?.alt;
const MAX_HEIGHT_DIFF: f32 = 5.0;
if this.get(pos + Vec2::new(1, 0))?.alt + MAX_HEIGHT_DIFF < alt {
pos.x += 1;
}
if this.get(pos + Vec2::new(-1, 0))?.alt + MAX_HEIGHT_DIFF < alt {
pos.x -= 1;
}
if this.get(pos + Vec2::new(0, 1))?.alt + MAX_HEIGHT_DIFF < alt {
pos.y += 1;
}
if this.get(pos + Vec2::new(0, -1))?.alt + MAX_HEIGHT_DIFF < alt {
pos.y -= 1;
let chunk = this.get(pos)?;
for dir in [
Vec2::new(1, 0),
Vec2::new(-1, 0),
Vec2::new(0, 1),
Vec2::new(0, -1),
]
.iter()
{
const MAX_HEIGHT_DIFF: f32 = 8.0;
let tgt_chunk = this.get(pos + *dir)?;
if tgt_chunk.alt + MAX_HEIGHT_DIFF < chunk.alt
&& !tgt_chunk.is_underwater
{
pos += *dir;
}
}
if last_pos == pos {