AI Perception Behavior Enhancement: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(tweaks)
Line 1: Line 1:
[[Category:Programming]]
In HL2, if an idle NPC hears a sound but doesn't see its emitter, it will only turn in the direction of the sound for a time before returning to its previous action.
[[Category:AI Programming]]


==AI Perception behavior enhancement==
With the modification below the NPC will instead investigate the source of the sound.
 
In HL2, if a npc heard a sound but don't see the emiter of his one, it will keep staying in place. It will just turn in the direction of the sound for a time before redoing what it did before.
With the modification below the NPC will investigate the source of the sound.


Open the <code>ai_basenpc_schedule.cpp</code> file and look for the function <code>SelectAlertSchedule()</code>. Look for the following code:
Open the <code>ai_basenpc_schedule.cpp</code> file and look for the function <code>SelectAlertSchedule()</code>. Look for the following code:
Line 19: Line 15:
  }
  }


 
Replace this code with:
 
Replace this code by :
 


  if ( HasCondition ( COND_HEAR_DANGER ) ||
  if ( HasCondition ( COND_HEAR_DANGER ) ||
Line 36: Line 29:
==Conclusion==
==Conclusion==
With this code,as soon as NPC will hear alert sound, they will investigate.   
With this code,as soon as NPC will hear alert sound, they will investigate.   
I use this for my own project [http://www.eye.streumon-studio.com E.Y.E] and it runs perfectly.
I use this for my own project [http://eye.streumon-studio.com E.Y.E] and it runs perfectly.
 
[[Category:Programming]]
[[Category:AI Programming]]

Revision as of 14:00, 26 December 2006

In HL2, if an idle NPC hears a sound but doesn't see its emitter, it will only turn in the direction of the sound for a time before returning to its previous action.

With the modification below the NPC will instead investigate the source of the sound.

Open the ai_basenpc_schedule.cpp file and look for the function SelectAlertSchedule(). Look for the following code:

	if ( HasCondition ( COND_HEAR_DANGER ) ||
			  HasCondition ( COND_HEAR_PLAYER ) ||
			  HasCondition ( COND_HEAR_WORLD  ) ||
			  HasCondition ( COND_HEAR_BULLET_IMPACT ) ||
			  HasCondition ( COND_HEAR_COMBAT ) )
	{
		return SCHED_ALERT_FACE_BESTSOUND;

	}

Replace this code with:

	if ( HasCondition ( COND_HEAR_DANGER ) ||
			  HasCondition ( COND_HEAR_PLAYER ) ||
			  HasCondition ( COND_HEAR_WORLD  ) ||
			  HasCondition ( COND_HEAR_BULLET_IMPACT ) ||
			  HasCondition ( COND_HEAR_COMBAT ) )
	{
		
			  return SCHED_INVESTIGATE_SOUND;//E.Y.E , AI Search for the source of alert  sound
	}

Conclusion

With this code,as soon as NPC will hear alert sound, they will investigate. I use this for my own project E.Y.E and it runs perfectly.