瀏覽代碼

put the flocking protocol ion the repath command itself with a high weight so it prioritizes avoidance vs straight following

AzaezelX 5 月之前
父節點
當前提交
a609917cee
共有 3 個文件被更改,包括 28 次插入13 次删除
  1. 13 10
      Engine/source/T3D/AI/AIController.cpp
  2. 14 3
      Engine/source/T3D/AI/AINavigation.cpp
  3. 1 0
      Engine/source/T3D/AI/AINavigation.h

+ 13 - 10
Engine/source/T3D/AI/AIController.cpp

@@ -110,6 +110,7 @@ void AIController::setAim(SimObjectPtr<SceneObject> objIn, F32 rad, Point3F offs
 }
 
 #ifdef TORQUE_NAVIGATION_ENABLED
+
 bool AIController::getAIMove(Move* movePtr)
 {
    *movePtr = NullMove;
@@ -178,12 +179,17 @@ bool AIController::getAIMove(Move* movePtr)
             }
             getGoal()->mInRange = false;
          }
-         if (getGoal()->getDist() < mControllerData->mFollowTolerance && !getGoal()->mInRange)
+         if (getGoal()->getDist() < mControllerData->mFollowTolerance )
          {
             getNav()->clearPath();
             mMovement.mMoveState = ModeStop;
-            getGoal()->mInRange = true;
-            throwCallback("onTargetInRange");
+
+            if (!getGoal()->mInRange)
+            {
+               getGoal()->mInRange = true;
+               throwCallback("onTargetInRange");
+            }
+            else getGoal()->mInRange = false;
          }
          else
          {
@@ -195,14 +201,11 @@ bool AIController::getAIMove(Move* movePtr)
                   throwCallback("onTargetInFiringRange");
                }
             }
-            else
-               getGoal()->mInFiringRange = false;
+            else getGoal()->mInFiringRange = false;
          }
       }
    }
 #endif // TORQUE_NAVIGATION_ENABLED
-
-   getNav()->flock();
    // Orient towards the aim point, aim object, or towards
    // our destination.
    if (getAim() || mMovement.mMoveState != ModeStop)
@@ -472,8 +475,8 @@ void AIControllerData::resolveStuck(AIController* obj)
             if (obj->mMovement.mMoveState != AIController::ModeSlowing || locationDelta == 0)
             {
                obj->mMovement.onStuck();
+               obj->mMovement.mMoveStuckTestCountdown = obj->mControllerData->mMoveStuckTestDelay;
             }
-            obj->mMovement.mMoveStuckTestCountdown = obj->mControllerData->mMoveStuckTestDelay;
          }
       }
    }
@@ -489,10 +492,10 @@ AIControllerData::AIControllerData()
    mLinkTypes = LinkData(AllFlags);
    mNavSize = AINavigation::Regular;
 
-   mFlocking.mChance = 100;
+   mFlocking.mChance = 90;
    mFlocking.mMin = 1.0f;
    mFlocking.mMax = 3.0f;
-   mFlocking.mSideStep = 0.125f;
+   mFlocking.mSideStep = 0.01f;
 
    resolveYawPtr.bind(this, &AIControllerData::resolveYaw);
    resolvePitchPtr.bind(this, &AIControllerData::resolvePitch);

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

@@ -126,11 +126,21 @@ void AINavigation::repath()
    if (mPathData.path.isNull() || !mPathData.owned)
       return;
 
-   // If we're following, get their position.
-   mPathData.path->mTo = getCtrl()->getGoal()->getPosition();
+   if (mRandI(0, 100) < getCtrl()->mControllerData->mFlocking.mChance)
+   {
+      flock();
+      mPathData.path->mTo = mMoveDestination;
+   }
+   else
+   {
+      // If we're following, get their position.
+      mPathData.path->mTo = getCtrl()->getGoal()->getPosition();
+   }
+
    // Update from position and replan.
    mPathData.path->mFrom = getCtrl()->getAIInfo()->getPosition();
    mPathData.path->plan();
+
    // Move to first node (skip start pos).
    moveToNode(1);
 }
@@ -393,8 +403,9 @@ void AINavigation::flock()
          }
 
          //if we're not jumping...
-         if ((mPathData.path) && !(mPathData.path->getFlags(mPathData.index) & JumpFlag))
+         if (mJump == None)
          {
+            dest.z -= obj->getObjBox().len_z()*0.5;
             //make sure we don't run off a cliff
             Point3F zlen(0, 0, getCtrl()->getAIInfo()->mRadius);
             if (obj->getContainer()->castRay(dest + zlen, dest - zlen, TerrainObjectType | StaticShapeObjectType | StaticObjectType, &info))

+ 1 - 0
Engine/source/T3D/AI/AINavigation.h

@@ -70,6 +70,7 @@ struct AINavigation
    Point3F mMoveDestination;
    void setMoveDestination(const Point3F& location, bool slowdown);
    Point3F getMoveDestination() { return mMoveDestination; };
+
    void onReachDestination();
 
    /// NavMesh we pathfind on.