Fix alien controller facing in non combat state - FreeSlave/halflife-updated GitHub Wiki
The Problem
Alien controllers face wrong direction in non-combat state. This is rarely observed by a player as controllers have full field of view (controllers can see a player behind their back) and turn to a player a moment the player becomes visible. However the bug can be observed in some mods, e.g. if controllers are located behind the glass (and thus can be seen by a player) or if controller is set to ignore enemies (e.g. with Prisoner
flag) or set to friendly with player.
Note: the fix was merged into halflife-updated. If your project is based on halflife-updated, then merge/rebase upon the main repository.
The Research
Alien controllers are programmed to turn to the last known position of their enemy no matter what.
case TASK_WAIT_FOR_MOVEMENT:
case TASK_WAIT:
case TASK_WAIT_FACE_ENEMY:
case TASK_WAIT_PVS:
MakeIdealYaw(m_vecEnemyLKP);
ChangeYaw(pev->yaw_speed);
However m_vecEnemyLKP
is zero vector at the start of the game, so controllers turn to the center of the world.
The Solution
Go to the CController::RunTask
and change the code under TASK_WAIT_PVS
case:
-MakeIdealYaw(m_vecEnemyLKP);
-ChangeYaw(pev->yaw_speed);
+if (m_hEnemy != 0)
+{
+ MakeIdealYaw(m_vecEnemyLKP);
+ ChangeYaw(pev->yaw_speed);
+}