mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Merge branch 'fix_ai_wander' into 'master'
Limit AiWander destination by wander distance (#6937) Closes #6937 See merge request OpenMW/openmw!2353
This commit is contained in:
commit
fab5236fcd
@ -6,6 +6,7 @@
|
||||
Bug #5057: Weapon swing sound plays at same pitch whether it hits or misses
|
||||
Bug #5129: Stuttering animation on Centurion Archer
|
||||
Bug #5977: Fatigueless NPCs' corpse underwater changes animation on game load
|
||||
Bug #6937: Divided by Nix Hounds quest is broken
|
||||
Bug #6939: OpenMW-CS: ID columns are too short
|
||||
Bug #6949: Sun Damage effect doesn't work in quasi exteriors
|
||||
Bug #6964: Nerasa Dralor Won't Follow
|
||||
|
@ -360,14 +360,27 @@ namespace MWMechanics
|
||||
if (!isWaterCreature && !isFlyingCreature)
|
||||
{
|
||||
// findRandomPointAroundCircle uses wanderDistance as limit for random and not as exact distance
|
||||
if (const auto destination = DetourNavigator::findRandomPointAroundCircle(*navigator, agentBounds,
|
||||
mInitialActorPosition, wanderDistance, navigatorFlags, []() {
|
||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||
return Misc::Rng::rollProbability(prng);
|
||||
}))
|
||||
mDestination = *destination;
|
||||
else
|
||||
mDestination = getRandomPointAround(mInitialActorPosition, wanderRadius);
|
||||
const auto getRandom = []()
|
||||
{
|
||||
return Misc::Rng::rollProbability(MWBase::Environment::get().getWorld()->getPrng());
|
||||
};
|
||||
auto destination = DetourNavigator::findRandomPointAroundCircle(*navigator, agentBounds,
|
||||
mInitialActorPosition, wanderRadius, navigatorFlags, getRandom);
|
||||
if (destination.has_value())
|
||||
{
|
||||
osg::Vec3f direction = *destination - mInitialActorPosition;
|
||||
if (direction.length() > wanderDistance)
|
||||
{
|
||||
direction.normalize();
|
||||
const osg::Vec3f adjustedDestination = mInitialActorPosition + direction * wanderRadius;
|
||||
destination = DetourNavigator::raycast(*navigator, agentBounds, currentPosition,
|
||||
adjustedDestination, navigatorFlags);
|
||||
if (destination.has_value() && (*destination - mInitialActorPosition).length() > wanderDistance)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
mDestination = destination.has_value() ? *destination
|
||||
: getRandomPointAround(mInitialActorPosition, wanderRadius);
|
||||
}
|
||||
else
|
||||
mDestination = getRandomPointAround(mInitialActorPosition, wanderRadius);
|
||||
|
Loading…
x
Reference in New Issue
Block a user