1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-14 01:19:59 +00:00

Don't ignore Z in path finding if actor can move by Z.

This commit is contained in:
Petr Mikheev 2021-01-29 21:27:22 +01:00
parent 642ca02e35
commit 9590377f22
3 changed files with 17 additions and 6 deletions

View File

@ -96,6 +96,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
const float distToTarget = distance(position, dest);
const bool isDestReached = (distToTarget <= destTolerance);
const bool actorCanMoveByZ = canActorMoveByZAxis(actor);
if (!isDestReached && mTimer > AI_REACTION_TIME)
{
@ -104,7 +105,6 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
const bool wasShortcutting = mIsShortcutting;
bool destInLOS = false;
const bool actorCanMoveByZ = canActorMoveByZAxis(actor);
// Prohibit shortcuts for AiWander, if the actor can not move in 3 dimensions.
mIsShortcutting = actorCanMoveByZ
@ -151,7 +151,8 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
const float pointTolerance = std::max(MIN_TOLERANCE, actorTolerance);
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
mPathFinder.update(position, pointTolerance, DEFAULT_TOLERANCE, /*shortenIfAlmostStraight=*/smoothMovement);
mPathFinder.update(position, pointTolerance, DEFAULT_TOLERANCE,
/*shortenIfAlmostStraight=*/smoothMovement, actorCanMoveByZ);
if (isDestReached || mPathFinder.checkPathCompleted()) // if path is finished
{

View File

@ -296,7 +296,8 @@ namespace MWMechanics
return getXAngleToDir(dir);
}
void PathFinder::update(const osg::Vec3f& position, float pointTolerance, float destinationTolerance, bool shortenIfAlmostStraight)
void PathFinder::update(const osg::Vec3f& position, float pointTolerance, float destinationTolerance,
bool shortenIfAlmostStraight, bool canMoveByZ)
{
if (mPath.empty())
return;
@ -312,8 +313,16 @@ namespace MWMechanics
mPath.pop_front();
}
if (mPath.size() == 1 && sqrDistanceIgnoreZ(mPath.front(), position) < destinationTolerance * destinationTolerance)
mPath.pop_front();
if (mPath.size() == 1)
{
float distSqr;
if (canMoveByZ)
distSqr = (mPath.front() - position).length2();
else
distSqr = sqrDistanceIgnoreZ(mPath.front(), position);
if (distSqr < destinationTolerance * destinationTolerance)
mPath.pop_front();
}
}
void PathFinder::buildStraightPath(const osg::Vec3f& endPoint)

View File

@ -102,7 +102,8 @@ namespace MWMechanics
const DetourNavigator::Flags flags, const DetourNavigator::AreaCosts& areaCosts);
/// Remove front point if exist and within tolerance
void update(const osg::Vec3f& position, float pointTolerance, float destinationTolerance, bool shortenIfAlmostStraight);
void update(const osg::Vec3f& position, float pointTolerance, float destinationTolerance,
bool shortenIfAlmostStraight, bool canMoveByZ);
bool checkPathCompleted() const
{