<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.shootemupkit.com/wiki/index.php?action=history&amp;feed=atom&amp;title=AI_Events</id>
	<title>AI Events - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.shootemupkit.com/wiki/index.php?action=history&amp;feed=atom&amp;title=AI_Events"/>
	<link rel="alternate" type="text/html" href="https://www.shootemupkit.com/wiki/index.php?title=AI_Events&amp;action=history"/>
	<updated>2026-04-09T08:35:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://www.shootemupkit.com/wiki/index.php?title=AI_Events&amp;diff=10&amp;oldid=prev</id>
		<title>Wikiadmin: Created page with &quot;==AI States and Events==  In this tutorial we will create an NPC which waits until the player has fired a shot and then chases the player.   We...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.shootemupkit.com/wiki/index.php?title=AI_Events&amp;diff=10&amp;oldid=prev"/>
		<updated>2020-05-23T19:09:43Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==AI States and Events==  In this tutorial we will create an &lt;a href=&quot;/wiki/index.php?title=Add_an_NPC&quot; title=&quot;Add an NPC&quot;&gt;NPC&lt;/a&gt; which waits until the &lt;a href=&quot;/wiki/index.php?title=Add_a_Player&quot; title=&quot;Add a Player&quot;&gt;player&lt;/a&gt; has fired a shot and then chases the player.   We...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==AI States and Events==&lt;br /&gt;
&lt;br /&gt;
In this tutorial we will create an [[Add an NPC|NPC]] which waits until the [[Add a Player|player]] has fired a shot and then chases the player.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will do this using two ''AI States''.  The first will be the ''Default state'' and the NPC will just wait without any AI Behaviours.  The second state will be the ''Chase'' state and will use the ''Chase'' AI Behaviour.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The NPC will switch between the AI States by listening for an ''AI Event''.  We will set an Action so that when the player presses the fire button it will send an AI State for the NPC to respond to.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==AI States==&lt;br /&gt;
&lt;br /&gt;
A non-playing character ([[Add an NPC|NPC]]) can have multiple states.  A state can be thought of as the NPC’s current purpose or state of mind.  The NPC will only be in one state at a time but can move between different states.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Typical states for a videogame character are ''Idle'', ''Patrol'' and ''Attack''.  The NPC starts off in an ''Idle'' state and waits for a few seconds.  The NPC then moves into a ''Patrol'' state and follows a spline path.  If the NPC sees an enemy (either in the Idle state or the Patrol State) then they will move into the ''Attack'' state and will chase and fire at the enemy.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[File:AIEvents1.png|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each state will contain AI Behaviours such as ''Wait'', ''Move'', ''Follow'', ''Chase'' and ''Fire''.  These behaviours fulfil the purpose of the state, so an Attack state might use the ''Chase'' and ''Fire'' AI Behaviours.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
NPCs change which state they are currently using by generating or responding to AI events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==AI Events==&lt;br /&gt;
&lt;br /&gt;
An ''AI Event'' can be defined by clicking the [[File:AIEvents.png|link=]] ''AI Events'' button on the [[Define Menu|Definitions]] window and then creating a name for the event.  There are no other properties, an AI event is just a name (or a tag) which we can use to refer to it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An AI Event can be triggered from an ''Action'' event.  In the [[Actions Tab|Action tab]] of many types of object you can specify which AI Event should be triggered when the Action occurs (such as 50% damage, colliding with an object, or a button being pressed).&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[File:AIEvents2.png|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Change State AI Behaviours==&lt;br /&gt;
&lt;br /&gt;
There are many ''Change State'' behaviours which can be included within a state.  The ''Change State on [[Add a Timer|Timer]]'' behaviour can be used to automatically switch states once a duration of time has passed.  The ''Change State on Enemy Proximity'' state behaviour will change the NPCs state when it is within a specified distance of their current enemy.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[File:AIEvents3.png|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ''Change State'' behaviours allow you to control the flow between the states.  For example, an enemy Boss could be created by using states for each of the phases of the enemy’s attack.  The first phase would fire two weaker weapons which fire a lot of bullets in an intricate pattern.  The first phase would also use a ''Change State on Timer'' behaviour to switch to phase 2 after 5 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''Change State on AI Event'' is useful for responding to AI Events generated by Actions from other objects within the game.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example: Responding to the Player firing a Bullet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can add an [[Actions Tab|Action]] event for the Player and select the Fire 1 (Button Down) event.  The Action will trigger whenever the Player presses the Fire 1 button.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[File:AIEvents4.png|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We need to create an AI Event for the NPC to respond to.  We can click on the AI Event icon and create an AI Event.  We shall call this ''React to Firing'' and click the [OK] button.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[File:AIEvents5.png|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can now return to the [[Actions Tab|Action tab]] for the Player and find the ''Trigger AI Event'' property.  Clicking on ''None'' will open a list of AI Events that we’ve created, and we can select our ''React to Firing'' event.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
[[File:AIEvents6.png|link=]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We now need to set-up an NPC to respond to this event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, we need to go to the [[AI Tab|AI tab]] and, in the ''Default'' state, add an AI Behaviour.  Select ''Change State on AI Event'' from the list.  Once this has been added to the state, we can select which AI Event we want to react to.  This should be our new ''React to Firing'' event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The other property we need to set is the State we should be switching to.  We have only got one state at the moment and so we should create a new one by clicking the ''Add State'' button.  We shall call this new state ''Attack''.  We can also take the opportunity to add ''Fire'' and ''Chase'' behaviours to the ''Attack'' state.  Don’t forget to specify which Entity the NPC should chase.  We’ll make the NPC chase the player.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can now go back to the ''State'' property (in the ''Default'' state) and select the ''Attack'' state.&lt;br /&gt;
We are now all set-up.  When we start the game, the NPC will sit patiently until the player presses the fire button.  When this happens the NPC will switch into the attack state and will start firing and chasing the player.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AIEvents7.png|link=]]&lt;/div&gt;</summary>
		<author><name>Wikiadmin</name></author>
		
	</entry>
</feed>