Browse Source

simplify setpathdestination loop

AzaezelX 5 months ago
parent
commit
2956223a60
2 changed files with 5 additions and 5 deletions
  1. 2 2
      Engine/source/T3D/AI/AIController.cpp
  2. 3 3
      Engine/source/T3D/AI/AINavigation.cpp

+ 2 - 2
Engine/source/T3D/AI/AIController.cpp

@@ -78,11 +78,11 @@ bool AIController::getAIMove(Move* movePtr)
    Point3F rotation = sbo->getTransform().toEuler();
    Point3F rotation = sbo->getTransform().toEuler();
 
 
 #ifdef TORQUE_NAVIGATION_ENABLED
 #ifdef TORQUE_NAVIGATION_ENABLED
-   if (sbo->getDamageState() == ShapeBase::Enabled)
+   if (sbo->getDamageState() == ShapeBase::Enabled && getGoal())
    {
    {
       if (mMovement.mMoveState != ModeStop)
       if (mMovement.mMoveState != ModeStop)
          getNav()->updateNavMesh();
          getNav()->updateNavMesh();
-      if (getGoal() && !getGoal()->mObj.isNull())
+      if (getGoal()->mObj.isValid())
       {
       {
          if (getNav()->mPathData.path.isNull())
          if (getNav()->mPathData.path.isNull())
          {
          {

+ 3 - 3
Engine/source/T3D/AI/AINavigation.cpp

@@ -64,7 +64,6 @@ NavMesh* AINavigation::findNavMesh() const
 void AINavigation::updateNavMesh()
 void AINavigation::updateNavMesh()
 {
 {
    GameBase* gbo = dynamic_cast<GameBase*>(mControllerRef->getAIInfo()->mObj.getPointer());
    GameBase* gbo = dynamic_cast<GameBase*>(mControllerRef->getAIInfo()->mObj.getPointer());
-   NavMesh* old = mNavMesh;
    if (mNavMesh.isNull())
    if (mNavMesh.isNull())
       mNavMesh = findNavMesh();
       mNavMesh = findNavMesh();
    else
    else
@@ -73,9 +72,9 @@ void AINavigation::updateNavMesh()
          mNavMesh = findNavMesh();
          mNavMesh = findNavMesh();
    }
    }
    // See if we need to update our path.
    // See if we need to update our path.
-   if (mNavMesh != old && !mPathData.path.isNull())
+   if (mNavMesh)
    {
    {
-      setPathDestination(mPathData.path->mTo);
+      setPathDestination(getCtrl()->getGoal()->getPosition());
    }
    }
 }
 }
 
 
@@ -178,6 +177,7 @@ void AINavigation::onReachDestination()
 
 
 bool AINavigation::setPathDestination(const Point3F& pos)
 bool AINavigation::setPathDestination(const Point3F& pos)
 {
 {
+   if (!getCtrl()->getGoal()) getCtrl()->setGoal(pos, getCtrl()->mControllerData->mMoveTolerance);
    if (!mNavMesh)
    if (!mNavMesh)
       updateNavMesh();
       updateNavMesh();
    // If we can't find a mesh, just move regularly.
    // If we can't find a mesh, just move regularly.