ludic.wildlife (17.6): a fleeing or wary animal goes by the world's way

It sets a target straight away from the threat (40 m when it flees, 20 m when it is wary) and heads for it with wl_head, so the way port takes it round water and cliffs. Where the world gives no way, it still runs straight away as before. way_test now has a flee round the wall's end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 22:31:07 +03:00
parent f1153f59a2
commit 61f802e9ad
3 changed files with 40 additions and 2 deletions

View file

@ -34,3 +34,20 @@ function wl_pick_target(wildlife_st: WildlifeState, a: WildAnimal, radius: float
a.tz = WildlifeWorld.way_z()
}
}
# a target d metres straight away from (fx, fz): where it runs or backs off to, by the world's way -
# round water and a cliff where there is one, and straight away as before where there is not
function wl_away(a: WildAnimal, fx: float, fz: float, d: float) -> void {
var dx = a.x - fx
var dz = a.z - fz
let l = Math.sqrt(dx * dx + dz * dz)
if l < 0.01 {
dx = -Math.sin(a.yaw)
dz = -Math.cos(a.yaw)
} else {
dx = dx / l
dz = dz / l
}
a.tx = a.x + dx * d
a.tz = a.z + dz * d
}