Prohibit accidental cliff diving by NPCs

This commit is contained in:
James Melkonian 2022-01-25 16:25:40 +00:00 committed by Samuel Keiffer
parent 54d5a06a0d
commit 2671f824d0
2 changed files with 20 additions and 1 deletions

View File

@ -90,6 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Agents can flee once again, and more appropriately - Agents can flee once again, and more appropriately
- Items in hotbar no longer change when sorting inventory - Items in hotbar no longer change when sorting inventory
- Lantern color changes when swapping lanterns - Lantern color changes when swapping lanterns
- NPCs no longer wander off cliffs
## [0.11.0] - 2021-09-11 ## [0.11.0] - 2021-09-11

View File

@ -857,7 +857,8 @@ impl<'a> AgentData<'a> {
}); });
// Stop if we're too close to a wall // Stop if we're too close to a wall
// NOTE: costs 1 us (imbris) // or about to walk off a cliff
// NOTE: costs 1 us (imbris) <- before cliff raycast added
agent.bearing *= 0.1 agent.bearing *= 0.1
+ if read_data + if read_data
.terrain .terrain
@ -874,6 +875,23 @@ impl<'a> AgentData<'a> {
.cast() .cast()
.1 .1
.map_or(true, |b| b.is_none()) .map_or(true, |b| b.is_none())
&& read_data
.terrain
.ray(
self.pos.0
+ Vec3::from(agent.bearing)
.try_normalized()
.unwrap_or_else(Vec3::unit_y),
self.pos.0
+ Vec3::from(agent.bearing)
.try_normalized()
.unwrap_or_else(Vec3::unit_y)
- Vec3::unit_z() * 4.0,
)
.until(Block::is_solid)
.cast()
.0
< 3.0
{ {
0.9 0.9
} else { } else {