Browse Source

skip sidestepping off a cliff raycast if we're not sidestepping
take current velocity into account for vehicles since some degree of momentum will be maintained

AzaezelX 5 months ago
parent
commit
b2021caa6d
2 changed files with 23 additions and 21 deletions
  1. 3 3
      Engine/source/T3D/AI/AIController.cpp
  2. 20 18
      Engine/source/T3D/AI/AINavigation.cpp

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

@@ -670,7 +670,7 @@ void AIWheeledVehicleControllerData::resolveYaw(AIController* obj, Point3F locat
    Point3F aimLoc = obj->mMovement.mAimLocation;
    Point3F aimLoc = obj->mMovement.mAimLocation;
 
 
    // Get the AI to Target vector and normalize it.
    // Get the AI to Target vector and normalize it.
-   Point3F toTarg = location - aimLoc;
+   Point3F toTarg = (location + wvo->getVelocity() * TickSec) - aimLoc;
    toTarg.normalize();
    toTarg.normalize();
 
 
    F32 dotYaw = -mDot(right, toTarg);
    F32 dotYaw = -mDot(right, toTarg);
@@ -746,7 +746,7 @@ void AIFlyingVehicleControllerData::resolveYaw(AIController* obj, Point3F locati
    Point3F aimLoc = obj->mMovement.mAimLocation;
    Point3F aimLoc = obj->mMovement.mAimLocation;
 
 
    // Get the Target to AI vector and normalize it.
    // Get the Target to AI vector and normalize it.
-   Point3F toTarg = location - aimLoc;
+   Point3F toTarg = (location + fvo->getVelocity() * TickSec) - aimLoc;
    toTarg.normalize();
    toTarg.normalize();
 
 
    F32 dotYaw = -mDot(right, toTarg);
    F32 dotYaw = -mDot(right, toTarg);
@@ -774,7 +774,7 @@ void AIFlyingVehicleControllerData::resolvePitch(AIController* obj, Point3F loca
    aimLoc.z = mClampF(aimLoc.z, mFlightFloor, mFlightCeiling);
    aimLoc.z = mClampF(aimLoc.z, mFlightFloor, mFlightCeiling);
 
 
    // Get the Target to AI vector and normalize it.
    // Get the Target to AI vector and normalize it.
-   Point3F toTarg = location - aimLoc;
+   Point3F toTarg = (location + fvo->getVelocity() * TickSec) - aimLoc;
    toTarg.normalize();
    toTarg.normalize();
    F32 lastPitch = fvo->getSteering().y;
    F32 lastPitch = fvo->getSteering().y;
 
 

+ 20 - 18
Engine/source/T3D/AI/AINavigation.cpp

@@ -306,6 +306,7 @@ bool AINavigation::flock()
 
 
    F32 maxFlocksq = flockingData.mMax * flockingData.mMax;
    F32 maxFlocksq = flockingData.mMax * flockingData.mMax;
    bool flocking = false;
    bool flocking = false;
+   U32 found = 0;
    if (getCtrl()->getGoal())
    if (getCtrl()->getGoal())
    {
    {
       Point3F dest = mMoveDestination;
       Point3F dest = mMoveDestination;
@@ -327,7 +328,6 @@ bool AINavigation::flock()
          sql.mList.remove(obj);
          sql.mList.remove(obj);
 
 
          Point3F avoidanceOffset = Point3F::Zero;
          Point3F avoidanceOffset = Point3F::Zero;
-         U32 found = 0;
 
 
          //avoid objects in the way
          //avoid objects in the way
          RayInfo info;
          RayInfo info;
@@ -390,27 +390,29 @@ bool AINavigation::flock()
                }
                }
             }
             }
          }
          }
-
-         avoidanceOffset.z = 0;
-         avoidanceOffset.x = (mRandF() * avoidanceOffset.x) * 0.5 + avoidanceOffset.x * 0.75;
-         avoidanceOffset.y = (mRandF() * avoidanceOffset.y) * 0.5 + avoidanceOffset.y * 0.75;
-         if (avoidanceOffset.lenSquared() < (maxFlocksq))
+         if (found > 0)
          {
          {
-            dest += avoidanceOffset;
-         }
+            avoidanceOffset.z = 0;
+            avoidanceOffset.x = (mRandF() * avoidanceOffset.x) * 0.5 + avoidanceOffset.x * 0.75;
+            avoidanceOffset.y = (mRandF() * avoidanceOffset.y) * 0.5 + avoidanceOffset.y * 0.75;
+            if (avoidanceOffset.lenSquared() < (maxFlocksq))
+            {
+               dest += avoidanceOffset;
+            }
 
 
-         //if we're not jumping...
-         if (mJump == None)
-         {
-            dest.z = obj->getPosition().z;
-            //make sure we don't run off a cliff
-            Point3F zlen(0, 0, getCtrl()->mControllerData->mHeightTolerance);
-            if (obj->getContainer()->castRay(dest + zlen, dest - zlen, TerrainObjectType | StaticShapeObjectType | StaticObjectType, &info))
+            //if we're not jumping...
+            if (mJump == None)
             {
             {
-               if ((mMoveDestination - dest).len() > getCtrl()->mControllerData->mMoveTolerance)
+               dest.z = obj->getPosition().z;
+               //make sure we don't run off a cliff
+               Point3F zlen(0, 0, getCtrl()->mControllerData->mHeightTolerance);
+               if (obj->getContainer()->castRay(dest + zlen, dest - zlen, TerrainObjectType | StaticShapeObjectType | StaticObjectType, &info))
                {
                {
-                  mMoveDestination = dest;
-                  flocking = true;
+                  if ((mMoveDestination - dest).len() > getCtrl()->mControllerData->mMoveTolerance)
+                  {
+                     mMoveDestination = dest;
+                     flocking = true;
+                  }
                }
                }
             }
             }
          }
          }