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.
pull/593/head
elsid 4 years ago
parent f32e1790bc
commit 453e94ea9f
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -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;

Loading…
Cancel
Save