1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 14:45:39 +00:00

Use half extents for destination distance tolerance in AiEscort

For actors moving in water destination may be located at such z coordinate
that they can't reach.
This commit is contained in:
elsid 2021-03-23 23:59:45 +01:00
parent f32e1790bc
commit 453e94ea9f
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40

View file

@ -73,25 +73,25 @@ namespace MWMechanics
const MWWorld::Ptr follower = MWBase::Environment::get().getWorld()->getPtr(mTargetActorRefId, false);
const osg::Vec3f leaderPos = actor.getRefData().getPosition().asVec3();
const osg::Vec3f followerPos = follower.getRefData().getPosition().asVec3();
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(actor);
const float maxHalfExtent = std::max(halfExtents.x(), std::max(halfExtents.y(), halfExtents.z()));
if ((leaderPos - followerPos).length2() <= mMaxDist * mMaxDist)
{
const osg::Vec3f dest(mX, mY, mZ);
if (pathTo(actor, dest, duration)) //Returns true on path complete
if (pathTo(actor, dest, duration, maxHalfExtent)) //Returns true on path complete
{
mRemainingDuration = mDuration;
return true;
}
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(actor);
mMaxDist = std::max(halfExtents.x(), std::max(halfExtents.y(), halfExtents.z())) + 450.0f;
mMaxDist = maxHalfExtent + 450.0f;
}
else
{
// Stop moving if the player is too far away
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(actor, "idle3", 0, 1);
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(actor);
mMaxDist = std::max(halfExtents.x(), std::max(halfExtents.y(), halfExtents.z())) + 250.0f;
mMaxDist = maxHalfExtent + 250.0f;
}
return false;