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

This commit is contained in:
AzaezelX 2025-04-19 06:37:28 -05:00
parent 3210325f3f
commit a609917cee
3 changed files with 28 additions and 13 deletions

View file

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

View file

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

View file

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