diff --git a/Engine/source/T3D/AI/AIController.cpp b/Engine/source/T3D/AI/AIController.cpp index 7e383a5e8..237333f09 100644 --- a/Engine/source/T3D/AI/AIController.cpp +++ b/Engine/source/T3D/AI/AIController.cpp @@ -670,7 +670,7 @@ void AIWheeledVehicleControllerData::resolveYaw(AIController* obj, Point3F locat Point3F aimLoc = obj->mMovement.mAimLocation; // Get the AI to Target vector and normalize it. - Point3F toTarg = location - aimLoc; + Point3F toTarg = (location + wvo->getVelocity() * TickSec) - aimLoc; toTarg.normalize(); F32 dotYaw = -mDot(right, toTarg); @@ -746,7 +746,7 @@ void AIFlyingVehicleControllerData::resolveYaw(AIController* obj, Point3F locati Point3F aimLoc = obj->mMovement.mAimLocation; // Get the Target to AI vector and normalize it. - Point3F toTarg = location - aimLoc; + Point3F toTarg = (location + fvo->getVelocity() * TickSec) - aimLoc; toTarg.normalize(); F32 dotYaw = -mDot(right, toTarg); @@ -774,7 +774,7 @@ void AIFlyingVehicleControllerData::resolvePitch(AIController* obj, Point3F loca aimLoc.z = mClampF(aimLoc.z, mFlightFloor, mFlightCeiling); // Get the Target to AI vector and normalize it. - Point3F toTarg = location - aimLoc; + Point3F toTarg = (location + fvo->getVelocity() * TickSec) - aimLoc; toTarg.normalize(); F32 lastPitch = fvo->getSteering().y; diff --git a/Engine/source/T3D/AI/AINavigation.cpp b/Engine/source/T3D/AI/AINavigation.cpp index 9534313ea..f5d3fd2cd 100644 --- a/Engine/source/T3D/AI/AINavigation.cpp +++ b/Engine/source/T3D/AI/AINavigation.cpp @@ -306,6 +306,7 @@ bool AINavigation::flock() F32 maxFlocksq = flockingData.mMax * flockingData.mMax; bool flocking = false; + U32 found = 0; if (getCtrl()->getGoal()) { Point3F dest = mMoveDestination; @@ -327,7 +328,6 @@ bool AINavigation::flock() sql.mList.remove(obj); Point3F avoidanceOffset = Point3F::Zero; - U32 found = 0; //avoid objects in the way 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; - } - - //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)) + 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 ((mMoveDestination - dest).len() > getCtrl()->mControllerData->mMoveTolerance) + 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)) { - mMoveDestination = dest; - flocking = true; + if ((mMoveDestination - dest).len() > getCtrl()->mControllerData->mMoveTolerance) + { + mMoveDestination = dest; + flocking = true; + } } } }