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
This commit is contained in:
AzaezelX 2025-04-25 20:36:22 -05:00
parent 675bdfe6b3
commit b2021caa6d
2 changed files with 24 additions and 22 deletions

View file

@ -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;

View file

@ -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()
} }
} }
} }
if (found > 0)
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; 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 we're not jumping... if (avoidanceOffset.lenSquared() < (maxFlocksq))
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 ((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; if ((mMoveDestination - dest).len() > getCtrl()->mControllerData->mMoveTolerance)
flocking = true; {
mMoveDestination = dest;
flocking = true;
}
} }
} }
} }