mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix NPC navigation near obstacles
Unwalkable obstacles, such as walls or open space can affect path-finding. We need to use precise calculation to avoid NPC being stuck in corser and near sharp turns.
This commit is contained in:
parent
529bcd7119
commit
c8f39e3beb
@ -131,7 +131,8 @@ impl Route {
|
||||
return None;
|
||||
}
|
||||
|
||||
let be_precise = DIAGONALS.iter().any(|pos| {
|
||||
// If, in any direction, there is a column of open air of several blocks
|
||||
let open_space_nearby = DIAGONALS.iter().any(|pos| {
|
||||
(-1..2).all(|z| {
|
||||
vol.get(next0 + Vec3::new(pos.x, pos.y, z))
|
||||
.map(|b| !b.is_solid())
|
||||
@ -139,6 +140,18 @@ impl Route {
|
||||
})
|
||||
});
|
||||
|
||||
// If, in any direction, there is a solid wall
|
||||
let wall_nearby = DIAGONALS.iter().any(|pos| {
|
||||
(0..2).all(|z| {
|
||||
vol.get(next0 + Vec3::new(pos.x, pos.y, z))
|
||||
.map(|b| b.is_solid())
|
||||
.unwrap_or(true)
|
||||
})
|
||||
});
|
||||
|
||||
// Unwalkable obstacles, such as walls or open space can affect path-finding
|
||||
let be_precise = open_space_nearby | wall_nearby;
|
||||
|
||||
// Map position of node to middle of block
|
||||
let next_tgt = next0.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0);
|
||||
let closest_tgt = next_tgt.map2(pos, |tgt, pos| pos.clamped(tgt.floor(), tgt.ceil()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user