mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
go ahead and allow follow without needing a navmesh
This commit is contained in:
parent
a05ff4f351
commit
e489e0cd18
4 changed files with 63 additions and 53 deletions
|
|
@ -201,14 +201,16 @@ bool AIController::getAIMove(Move* movePtr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (getGoal()->getDist() > mControllerData->mMoveTolerance)
|
if (getGoal()->getDist() > mControllerData->mFollowTolerance)
|
||||||
{
|
{
|
||||||
if (getGoal()->mPosSet)
|
if (getGoal()->mObj.isValid())
|
||||||
|
getNav()->followObject(getGoal()->mObj, mControllerData->mFollowTolerance);
|
||||||
|
else if (getGoal()->mPosSet)
|
||||||
getNav()->setPathDestination(getGoal()->getPosition(true));
|
getNav()->setPathDestination(getGoal()->getPosition(true));
|
||||||
|
|
||||||
getGoal()->mInRange = false;
|
getGoal()->mInRange = false;
|
||||||
}
|
}
|
||||||
if (getGoal()->getDist() < mControllerData->mMoveTolerance)
|
if (getGoal()->getDist() < mControllerData->mFollowTolerance)
|
||||||
{
|
{
|
||||||
mMovement.mMoveState = ModeStop;
|
mMovement.mMoveState = ModeStop;
|
||||||
|
|
||||||
|
|
@ -519,9 +521,9 @@ AIControllerData::AIControllerData()
|
||||||
mMoveStuckTolerance = 0.01f;
|
mMoveStuckTolerance = 0.01f;
|
||||||
mMoveStuckTestDelay = 30;
|
mMoveStuckTestDelay = 30;
|
||||||
mHeightTolerance = 0.001f;
|
mHeightTolerance = 0.001f;
|
||||||
|
mFollowTolerance = 1.0f;
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
mFollowTolerance = 1.0f;
|
|
||||||
mLinkTypes = LinkData(AllFlags);
|
mLinkTypes = LinkData(AllFlags);
|
||||||
mNavSize = AINavigation::Regular;
|
mNavSize = AINavigation::Regular;
|
||||||
mFlocking.mChance = 90;
|
mFlocking.mChance = 90;
|
||||||
|
|
@ -544,9 +546,9 @@ AIControllerData::AIControllerData(const AIControllerData& other, bool temp_clon
|
||||||
mMoveStuckTolerance = other.mMoveStuckTolerance;
|
mMoveStuckTolerance = other.mMoveStuckTolerance;
|
||||||
mMoveStuckTestDelay = other.mMoveStuckTestDelay;
|
mMoveStuckTestDelay = other.mMoveStuckTestDelay;
|
||||||
mHeightTolerance = other.mHeightTolerance;
|
mHeightTolerance = other.mHeightTolerance;
|
||||||
|
mFollowTolerance = other.mFollowTolerance;
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
mFollowTolerance = other.mFollowTolerance;
|
|
||||||
mLinkTypes = other.mLinkTypes;
|
mLinkTypes = other.mLinkTypes;
|
||||||
mNavSize = other.mNavSize;
|
mNavSize = other.mNavSize;
|
||||||
mFlocking.mChance = other.mFlocking.mChance;
|
mFlocking.mChance = other.mFlocking.mChance;
|
||||||
|
|
@ -575,6 +577,13 @@ void AIControllerData::initPersistFields()
|
||||||
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
||||||
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
||||||
|
|
||||||
|
addFieldV("followTolerance", TypeRangedF32, Offset(mFollowTolerance, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
|
"@brief Distance from destination before stopping.\n\n"
|
||||||
|
"When the AIController controlled object is moving to a given destination it will move to within "
|
||||||
|
"this distance of the destination and then stop. By providing this tolerance "
|
||||||
|
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
||||||
|
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
||||||
|
|
||||||
addFieldV("AttackRadius", TypeRangedF32, Offset(mAttackRadius, AIControllerData), &CommonValidators::PositiveFloat,
|
addFieldV("AttackRadius", TypeRangedF32, Offset(mAttackRadius, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
"@brief Distance considered in firing range for callback purposes.");
|
"@brief Distance considered in firing range for callback purposes.");
|
||||||
|
|
||||||
|
|
@ -601,12 +610,6 @@ void AIControllerData::initPersistFields()
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
addGroup("Pathfinding");
|
addGroup("Pathfinding");
|
||||||
addFieldV("followTolerance", TypeRangedF32, Offset(mFollowTolerance, AIControllerData), &CommonValidators::PositiveFloat,
|
|
||||||
"@brief Distance from destination before stopping.\n\n"
|
|
||||||
"When the AIController controlled object is moving to a given destination it will move to within "
|
|
||||||
"this distance of the destination and then stop. By providing this tolerance "
|
|
||||||
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
|
||||||
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
|
||||||
addFieldV("FlockChance", TypeRangedS32, Offset(mFlocking.mChance, AIControllerData), &CommonValidators::S32Percent,
|
addFieldV("FlockChance", TypeRangedS32, Offset(mFlocking.mChance, AIControllerData), &CommonValidators::S32Percent,
|
||||||
"@brief chance of flocking.");
|
"@brief chance of flocking.");
|
||||||
addFieldV("FlockMin", TypeRangedF32, Offset(mFlocking.mMin, AIControllerData), &CommonValidators::PositiveFloat,
|
addFieldV("FlockMin", TypeRangedF32, Offset(mFlocking.mMin, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
|
|
@ -645,8 +648,9 @@ void AIControllerData::packData(BitStream* stream)
|
||||||
stream->write(mMoveStuckTolerance);
|
stream->write(mMoveStuckTolerance);
|
||||||
stream->write(mMoveStuckTestDelay);
|
stream->write(mMoveStuckTestDelay);
|
||||||
stream->write(mHeightTolerance);
|
stream->write(mHeightTolerance);
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
stream->write(mFollowTolerance);
|
stream->write(mFollowTolerance);
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
//enums
|
//enums
|
||||||
stream->write(mLinkTypes.getFlags());
|
stream->write(mLinkTypes.getFlags());
|
||||||
stream->write((U32)mNavSize);
|
stream->write((U32)mNavSize);
|
||||||
|
|
@ -667,9 +671,9 @@ void AIControllerData::unpackData(BitStream* stream)
|
||||||
stream->read(&mMoveStuckTolerance);
|
stream->read(&mMoveStuckTolerance);
|
||||||
stream->read(&mMoveStuckTestDelay);
|
stream->read(&mMoveStuckTestDelay);
|
||||||
stream->read(&mHeightTolerance);
|
stream->read(&mHeightTolerance);
|
||||||
|
stream->read(&mFollowTolerance);
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
stream->read(&mFollowTolerance);
|
|
||||||
//enums
|
//enums
|
||||||
U16 linkFlags;
|
U16 linkFlags;
|
||||||
stream->read(&linkFlags);
|
stream->read(&linkFlags);
|
||||||
|
|
|
||||||
|
|
@ -153,12 +153,12 @@ public:
|
||||||
DECLARE_CONOBJECT(AIControllerData);
|
DECLARE_CONOBJECT(AIControllerData);
|
||||||
|
|
||||||
F32 mMoveTolerance; // Distance from destination point before we stop
|
F32 mMoveTolerance; // Distance from destination point before we stop
|
||||||
|
F32 mFollowTolerance; // Distance from destination object before we stop
|
||||||
F32 mAttackRadius; // Distance to trigger weaponry calcs
|
F32 mAttackRadius; // Distance to trigger weaponry calcs
|
||||||
S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck
|
S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck
|
||||||
F32 mMoveStuckTolerance; // Distance tolerance on stuck check
|
F32 mMoveStuckTolerance; // Distance tolerance on stuck check
|
||||||
F32 mHeightTolerance; // how high above the navmesh are we before we stop trying to repath
|
F32 mHeightTolerance; // how high above the navmesh are we before we stop trying to repath
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
F32 mFollowTolerance; // Distance from destination object before we stop
|
|
||||||
struct Flocking {
|
struct Flocking {
|
||||||
U32 mChance; // chance of flocking
|
U32 mChance; // chance of flocking
|
||||||
F32 mMin; // min flocking separation distance
|
F32 mMin; // min flocking separation distance
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,30 @@ void AINavigation::onReachDestination()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AINavigation::followObject()
|
||||||
|
{
|
||||||
|
if (getCtrl()->getGoal()->getDist() < getCtrl()->mControllerData->mMoveTolerance)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (setPathDestination(getCtrl()->getGoal()->getPosition(true)))
|
||||||
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
getCtrl()->clearCover();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AINavigation::followObject(SceneObject* obj, F32 radius)
|
||||||
|
{
|
||||||
|
getCtrl()->setGoal(obj, radius);
|
||||||
|
followObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AINavigation::clearFollow()
|
||||||
|
{
|
||||||
|
getCtrl()->clearGoal();
|
||||||
|
}
|
||||||
|
|
||||||
DefineEngineMethod(AIController, setMoveDestination, void, (Point3F goal, bool slowDown), (true),
|
DefineEngineMethod(AIController, setMoveDestination, void, (Point3F goal, bool slowDown), (true),
|
||||||
"@brief Tells the AI to move to the location provided\n\n"
|
"@brief Tells the AI to move to the location provided\n\n"
|
||||||
|
|
||||||
|
|
@ -210,6 +234,23 @@ DefineEngineMethod(AIController, getPathDestination, Point3F, (), ,
|
||||||
return object->getNav()->getPathDestination();
|
return object->getNav()->getPathDestination();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(AIController, followObject, void, (SimObjectId obj, F32 radius), ,
|
||||||
|
"@brief Tell the AIPlayer to follow another object.\n\n"
|
||||||
|
|
||||||
|
"@param obj ID of the object to follow.\n"
|
||||||
|
"@param radius Maximum distance we let the target escape to.")
|
||||||
|
{
|
||||||
|
SceneObject* follow;
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
object->getNav()->clearPath();
|
||||||
|
object->clearCover();
|
||||||
|
#endif
|
||||||
|
object->getNav()->clearFollow();
|
||||||
|
|
||||||
|
if (Sim::findObject(obj, follow))
|
||||||
|
object->getNav()->followObject(follow, radius);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
NavMesh* AINavigation::findNavMesh() const
|
NavMesh* AINavigation::findNavMesh() const
|
||||||
{
|
{
|
||||||
|
|
@ -315,27 +356,6 @@ void AINavigation::repath()
|
||||||
moveToNode(1);
|
moveToNode(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AINavigation::followObject()
|
|
||||||
{
|
|
||||||
if (getCtrl()->getGoal()->getDist() < getCtrl()->mControllerData->mMoveTolerance)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (setPathDestination(getCtrl()->getGoal()->getPosition(true)))
|
|
||||||
{
|
|
||||||
getCtrl()->clearCover();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINavigation::followObject(SceneObject* obj, F32 radius)
|
|
||||||
{
|
|
||||||
getCtrl()->setGoal(obj, radius);
|
|
||||||
followObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINavigation::clearFollow()
|
|
||||||
{
|
|
||||||
getCtrl()->clearGoal();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINavigation::followNavPath(NavPath* path)
|
void AINavigation::followNavPath(NavPath* path)
|
||||||
{
|
{
|
||||||
|
|
@ -497,21 +517,6 @@ DefineEngineMethod(AIController, followNavPath, void, (SimObjectId obj), ,
|
||||||
object->getNav()->followNavPath(path);
|
object->getNav()->followNavPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineMethod(AIController, followObject, void, (SimObjectId obj, F32 radius), ,
|
|
||||||
"@brief Tell the AIPlayer to follow another object.\n\n"
|
|
||||||
|
|
||||||
"@param obj ID of the object to follow.\n"
|
|
||||||
"@param radius Maximum distance we let the target escape to.")
|
|
||||||
{
|
|
||||||
SceneObject* follow;
|
|
||||||
object->getNav()->clearPath();
|
|
||||||
object->clearCover();
|
|
||||||
object->getNav()->clearFollow();
|
|
||||||
|
|
||||||
if (Sim::findObject(obj, follow))
|
|
||||||
object->getNav()->followObject(follow, radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DefineEngineMethod(AIController, repath, void, (), ,
|
DefineEngineMethod(AIController, repath, void, (), ,
|
||||||
"@brief Tells the AI to re-plan its path. Does nothing if the character "
|
"@brief Tells the AI to re-plan its path. Does nothing if the character "
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ struct AINavigation
|
||||||
|
|
||||||
void onReachDestination();
|
void onReachDestination();
|
||||||
|
|
||||||
|
void followObject();
|
||||||
|
void followObject(SceneObject* obj, F32 radius);
|
||||||
|
void clearFollow();
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
/// Stores information about a path.
|
/// Stores information about a path.
|
||||||
struct PathData {
|
struct PathData {
|
||||||
|
|
@ -92,9 +96,6 @@ struct AINavigation
|
||||||
SimObjectPtr<NavPath> getPath() { return mPathData.path; };
|
SimObjectPtr<NavPath> getPath() { return mPathData.path; };
|
||||||
void followNavPath(NavPath* path);
|
void followNavPath(NavPath* path);
|
||||||
|
|
||||||
void followObject();
|
|
||||||
void followObject(SceneObject* obj, F32 radius);
|
|
||||||
void clearFollow();
|
|
||||||
/// Move to the specified node in the current path.
|
/// Move to the specified node in the current path.
|
||||||
void moveToNode(S32 node);
|
void moveToNode(S32 node);
|
||||||
bool flock();
|
bool flock();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue