Follower npcs acting out of PVS - FreeSlave/halflife-updated GitHub Wiki
In Half-Life a player moves faster than monsters, so following npcs can easily fall behind. Sometimes they also would just stop trying and never reach the player even if they're capable of building a route. So what's the issue?
If a monster fails to perform its AI schedule at some point it usually starts a fail schedule which consists of the following tasks:
Task_t tlFail[] =
{
{TASK_STOP_MOVING, 0},
{TASK_SET_ACTIVITY, (float)ACT_IDLE},
{TASK_WAIT, (float)2},
{TASK_WAIT_PVS, (float)0},
};
TASK_WAIT_PVS
is the root of the problem here. Look at RunTask
in dlls/schedule.cpp
:
case TASK_WAIT_PVS:
{
if (!FNullEnt(FIND_CLIENT_IN_PVS(edict())))
{
TaskComplete();
}
break;
}
This means that monster will just wait until player is in its PVS (Possible Visible Set). As a simple fix we can rewrite the condition:
- if (!FNullEnt(FIND_CLIENT_IN_PVS(edict())))
+ if (!FNullEnt(FIND_CLIENT_IN_PVS(edict())) || (m_hTargetEnt != 0 && m_hTargetEnt->IsPlayer()))
You might have a better way to detect that the monster is an ally monster following the player in your game code, so change it accordingly.