This is a session originally written for students at Bradley University (Peoria, IL).
It covers a very high level introduction to the concepts behind Game AI, and includes some examples of how we can begin to make characters in a game world perform actions and appear to be making intelligent decisions.
3. Who Am I
• PhD Student at University of Strathclyde
2
4. Who Am I
• PhD Student at University of Strathclyde
‣ BSc(Hons), MSc, MRes(Dist) in AI-related fields
2
5. Who Am I
• PhD Student at University of Strathclyde
‣ BSc(Hons), MSc, MRes(Dist) in AI-related fields
• Founding member of SAIG
2
6. Who Am I
• PhD Student at University of Strathclyde
‣ BSc(Hons), MSc, MRes(Dist) in AI-related fields
• Founding member of SAIG
• AltDevBlogADay author
2
7. Who Am I
• PhD Student at University of Strathclyde
‣ BSc(Hons), MSc, MRes(Dist) in AI-related fields
• Founding member of SAIG
• AltDevBlogADay author
• AltDevConf organiser
2
8. Who Am I
• PhD Student at University of Strathclyde
‣ BSc(Hons), MSc, MRes(Dist) in AI-related fields
• Founding member of SAIG
• AltDevBlogADay author
• AltDevConf organiser
• Board of Directors for IGDA Scotland
2
9. Who Am I
• PhD Student at University of Strathclyde
‣ BSc(Hons), MSc, MRes(Dist) in AI-related fields
• Founding member of SAIG
• AltDevBlogADay author
• AltDevConf organiser
• Board of Directors for IGDA Scotland
• Recipient of the 2012 Eric Dybsand Memorial AI
Scholarship to attend GDC
2
11. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
3
12. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
• This is not state of the art stuff, this is entry level
3
13. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
• This is not state of the art stuff, this is entry level
• We will be dealing with a mix of
3
14. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
• This is not state of the art stuff, this is entry level
• We will be dealing with a mix of
‣ Concepts
3
15. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
• This is not state of the art stuff, this is entry level
• We will be dealing with a mix of
‣ Concepts
‣ Examples
3
16. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
• This is not state of the art stuff, this is entry level
• We will be dealing with a mix of
‣ Concepts
‣ Examples
‣ Code
3
17. Game AI 101
• Today going to look at techniques to populate game
worlds with characters
• This is not state of the art stuff, this is entry level
• We will be dealing with a mix of
‣ Concepts
‣ Examples
‣ Code
• Assumes familiarity with Unity
3
19. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
4
20. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
‣ Interested in creating systems as smart as possible
4
21. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
‣ Interested in creating systems as smart as possible
‣ Optimal solutions to real-world problems
4
22. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
‣ Interested in creating systems as smart as possible
‣ Optimal solutions to real-world problems
• Game AI is a whole other thing
4
23. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
‣ Interested in creating systems as smart as possible
‣ Optimal solutions to real-world problems
• Game AI is a whole other thing
‣ Create “realistic simulations” of intelligence
4
24. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
‣ Interested in creating systems as smart as possible
‣ Optimal solutions to real-world problems
• Game AI is a whole other thing
‣ Create “realistic simulations” of intelligence
- E.g. Believable characters
4
25. Pure AI vs Game AI
• “Pure” AI is a scientific discipline
‣ Interested in creating systems as smart as possible
‣ Optimal solutions to real-world problems
• Game AI is a whole other thing
‣ Create “realistic simulations” of intelligence
- E.g. Believable characters
‣ Enhance the players experience
4
28. Pure AI vs Game AI
• Pure AI for an NPC would be to make it fight as
effectively as possible.
6
29. Pure AI vs Game AI
• Pure AI for an NPC would be to make it fight as
effectively as possible.
• Is that what we actually want to achieve?
6
30. Pure AI vs Game AI
• Pure AI for an NPC would be to make it fight as
effectively as possible.
• Is that what we actually want to achieve?
• Game AI aims to make an immersive experience
6
31. Pure AI vs Game AI
• Pure AI for an NPC would be to make it fight as
effectively as possible.
• Is that what we actually want to achieve?
• Game AI aims to make an immersive experience
‣ Represent a thug character accurately
6
32. Pure AI vs Game AI
• Pure AI for an NPC would be to make it fight as
effectively as possible.
• Is that what we actually want to achieve?
• Game AI aims to make an immersive experience
‣ Represent a thug character accurately
‣ Allow the player to “become” Batman
6
33. Pure AI vs Game AI
• Pure AI for an NPC would be to make it fight as
effectively as possible.
• Is that what we actually want to achieve?
• Game AI aims to make an immersive experience
‣ Represent a thug character accurately
‣ Allow the player to “become” Batman
• Entertainment, not problem solving
6
36. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
7
37. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
‣ First video game example - Pong 1972
7
38. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
‣ First video game example - Pong 1972
‣ Ongoing commercial interest - FPS “Bots” RTS “Skirmish”
7
39. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
‣ First video game example - Pong 1972
‣ Ongoing commercial interest - FPS “Bots” RTS “Skirmish”
7
40. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
‣ First video game example - Pong 1972
‣ Ongoing commercial interest - FPS “Bots” RTS “Skirmish”
• Emphasis now on delivering a good player
experience.
7
41. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
‣ First video game example - Pong 1972
‣ Ongoing commercial interest - FPS “Bots” RTS “Skirmish”
• Emphasis now on delivering a good player
experience.
‣ Human-like rather than “good” AI
7
42. Automated Opponents
• Centuries of trying to play games with few players
‣ Mechanical Turk claimed to be a chess player circa 1770
‣ First video game example - Pong 1972
‣ Ongoing commercial interest - FPS “Bots” RTS “Skirmish”
• Emphasis now on delivering a good player
experience.
‣ Human-like rather than “good” AI
‣ Sub-human in order to be beatable
7
45. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
8
46. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
‣ Being Smart
8
47. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
‣ Being Smart
• Focus in this session on “Being Smart”
8
48. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
‣ Being Smart
• Focus in this session on “Being Smart”
• Looking Smart is more of an animation / art issue
8
49. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
‣ Being Smart
• Focus in this session on “Being Smart”
• Looking Smart is more of an animation / art issue
‣ Does the character “feel” intelligent
8
50. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
‣ Being Smart
• Focus in this session on “Being Smart”
• Looking Smart is more of an animation / art issue
‣ Does the character “feel” intelligent
• Good decision making still required to drive this
8
51. Looking and Being Smart
• Two components to Game AI
‣ Looking Smart
‣ Being Smart
• Focus in this session on “Being Smart”
• Looking Smart is more of an animation / art issue
‣ Does the character “feel” intelligent
• Good decision making still required to drive this
‣ Be smart, then trigger equivalent “look smart”
8
54. What is
Artificial Intelligence?
• Any time a computer has to pick between two or
more choices it can be said it is acting “intelligently”
10
55. What is
Artificial Intelligence?
• Any time a computer has to pick between two or
more choices it can be said it is acting “intelligently”
• That isn’t to say that it is inherently making good
choices.
10
56. What is
Artificial Intelligence?
• Any time a computer has to pick between two or
more choices it can be said it is acting “intelligently”
• That isn’t to say that it is inherently making good
choices.
‣ Tho neither do people...
10
57. What is
Artificial Intelligence?
• Any time a computer has to pick between two or
more choices it can be said it is acting “intelligently”
• That isn’t to say that it is inherently making good
choices.
‣ Tho neither do people...
• Typically, looking for better-than-random levels of
sophistication
10
59. Decision Making
• Not going to get too bogged down today in
decision making process.
11
60. Decision Making
• Not going to get too bogged down today in
decision making process.
• Science of decisions can fill multiple degree-level
courses
11
61. Decision Making
• Not going to get too bogged down today in
decision making process.
• Science of decisions can fill multiple degree-level
courses
• Game Theory is a good starting point to learn more
11
62. Decision Making
• Not going to get too bogged down today in
decision making process.
• Science of decisions can fill multiple degree-level
courses
• Game Theory is a good starting point to learn more
‣ “Behavioral Mathematics for Game AI” Dave Mark
11
64. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
12
65. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
‣ Making a decision is a good start
12
66. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
‣ Making a decision is a good start
• Partly because of the entertainment issue
12
67. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
‣ Making a decision is a good start
• Partly because of the entertainment issue
‣ Making good decisions is irrelevant
12
68. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
‣ Making a decision is a good start
• Partly because of the entertainment issue
‣ Making good decisions is irrelevant
‣ We don’t want tactical genius soldiers
12
69. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
‣ Making a decision is a good start
• Partly because of the entertainment issue
‣ Making good decisions is irrelevant
‣ We don’t want tactical genius soldiers
• Partly for rapid iteration
12
70. Smart or Dumb?
• Partly ignoring decision making because for Game
AI, it isn’t so important for intro level.
‣ Making a decision is a good start
• Partly because of the entertainment issue
‣ Making good decisions is irrelevant
‣ We don’t want tactical genius soldiers
• Partly for rapid iteration
‣ Make any decision, figure out how to make it better later
12
73. Agent-Based Systems
• Intelligent Agents are things within our problem that
are going to be trying to act intelligently.
13
74. Agent-Based Systems
• Intelligent Agents are things within our problem that
are going to be trying to act intelligently.
• Could be a Roomba, a warehouse robot, an
automated trip booking system or a predator drone
13
75. Agent-Based Systems
• Intelligent Agents are things within our problem that
are going to be trying to act intelligently.
• Could be a Roomba, a warehouse robot, an
automated trip booking system or a predator drone
• Agents have three important characteristics
13
76. Agent-Based Systems
• Intelligent Agents are things within our problem that
are going to be trying to act intelligently.
• Could be a Roomba, a warehouse robot, an
automated trip booking system or a predator drone
• Agents have three important characteristics
‣ Sense the environment
13
77. Agent-Based Systems
• Intelligent Agents are things within our problem that
are going to be trying to act intelligently.
• Could be a Roomba, a warehouse robot, an
automated trip booking system or a predator drone
• Agents have three important characteristics
‣ Sense the environment
‣ “Think” about what to do
13
78. Agent-Based Systems
• Intelligent Agents are things within our problem that
are going to be trying to act intelligently.
• Could be a Roomba, a warehouse robot, an
automated trip booking system or a predator drone
• Agents have three important characteristics
‣ Sense the environment
‣ “Think” about what to do
‣ Turn “thinking” into actions within the environment
13
81. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
14
82. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
• Each NPC is an agent.
14
83. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
• Each NPC is an agent.
‣ In some situations we may have a “General” as the agent
14
84. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
• Each NPC is an agent.
‣ In some situations we may have a “General” as the agent
- Directing NPCs around as its way of affecting the world.
14
85. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
• Each NPC is an agent.
‣ In some situations we may have a “General” as the agent
- Directing NPCs around as its way of affecting the world.
• In this model
14
86. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
• Each NPC is an agent.
‣ In some situations we may have a “General” as the agent
- Directing NPCs around as its way of affecting the world.
• In this model
‣ NPCs sense the world
14
87. NPCs as Agents
• One of the core places we can apply “agent-based
systems” is when thinking about NPCs
• Each NPC is an agent.
‣ In some situations we may have a “General” as the agent
- Directing NPCs around as its way of affecting the world.
• In this model
‣ NPCs sense the world
‣ Decide what to do, then do it
14
90. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
15
91. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
15
92. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
- Communal blackboard!
15
93. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
- Communal blackboard!
‣ Modern Squad - Communication between certain units
15
94. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
- Communal blackboard!
‣ Modern Squad - Communication between certain units
- This was made explicit in “Enslaved Odyssey to the West”
15
95. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
- Communal blackboard!
‣ Modern Squad - Communication between certain units
- This was made explicit in “Enslaved Odyssey to the West”
- Message passing between units
15
96. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
- Communal blackboard!
‣ Modern Squad - Communication between certain units
- This was made explicit in “Enslaved Odyssey to the West”
- Message passing between units
‣ Medieval Guards - No widespread communication
15
97. Representations
• Software Engineering buzzwords!
• Representation internal to one NPC or shared?
‣ Alien Hivemind - All units know what one unit knows
- Communal blackboard!
‣ Modern Squad - Communication between certain units
- This was made explicit in “Enslaved Odyssey to the West”
- Message passing between units
‣ Medieval Guards - No widespread communication
- Pure-internal representation
15
100. Taking Our First Steps
• For this session let’s assume we have
17
101. Taking Our First Steps
• For this session let’s assume we have
‣ A 3D world
17
102. Taking Our First Steps
• For this session let’s assume we have
‣ A 3D world
‣ A pre-fab for an NPC
17
103. Taking Our First Steps
• For this session let’s assume we have
‣ A 3D world
‣ A pre-fab for an NPC
- Surprise! We’ll be using the Unity soldier today
17
104. Taking Our First Steps
• For this session let’s assume we have
‣ A 3D world
‣ A pre-fab for an NPC
- Surprise! We’ll be using the Unity soldier today
• We’re going to work today with FPS, but the
techniques generalise fine.
17
105. Taking Our First Steps
• For this session let’s assume we have
‣ A 3D world
‣ A pre-fab for an NPC
- Surprise! We’ll be using the Unity soldier today
• We’re going to work today with FPS, but the
techniques generalise fine.
• Examples today come primarily from Steve
Gargolinski ( http://stevegargolinski.com )
17
108. Moving at Random
• OK, let’s do something basic
‣ Take our NPC, pick a location and go there.
18
109. Moving at Random
• OK, let’s do something basic
‣ Take our NPC, pick a location and go there.
‣ When he gets there, pick another location etc.
18
110. Moving at Random
• OK, let’s do something basic
‣ Take our NPC, pick a location and go there.
‣ When he gets there, pick another location etc.
• We need to
18
111. Moving at Random
• OK, let’s do something basic
‣ Take our NPC, pick a location and go there.
‣ When he gets there, pick another location etc.
• We need to
‣ Pick a location randomly
18
112. Moving at Random
• OK, let’s do something basic
‣ Take our NPC, pick a location and go there.
‣ When he gets there, pick another location etc.
• We need to
‣ Pick a location randomly
‣ Be able to move the NPC about
18
113. Moving at Random
• OK, let’s do something basic
‣ Take our NPC, pick a location and go there.
‣ When he gets there, pick another location etc.
• We need to
‣ Pick a location randomly
‣ Be able to move the NPC about
‣ Be able to detect when we get to the location
18
118. Following the Player
• Let’s do something a bit more sophisticated
‣ Follow the player around the map
20
119. Following the Player
• Let’s do something a bit more sophisticated
‣ Follow the player around the map
• This time we need to
20
120. Following the Player
• Let’s do something a bit more sophisticated
‣ Follow the player around the map
• This time we need to
‣ Determine position of the target
20
121. Following the Player
• Let’s do something a bit more sophisticated
‣ Follow the player around the map
• This time we need to
‣ Determine position of the target
‣ Move towards the target
20
122. Following the Player
• Let’s do something a bit more sophisticated
‣ Follow the player around the map
• This time we need to
‣ Determine position of the target
‣ Move towards the target
• Very similar to the last example, this time we have a
non-random target
20
126. On Patrol
• Typically, we want soldiers guarding things, patrolling
22
127. On Patrol
• Typically, we want soldiers guarding things, patrolling
‣ Go to the next waypoint
22
128. On Patrol
• Typically, we want soldiers guarding things, patrolling
‣ Go to the next waypoint
‣ When you get there, go to the next in the series etc
22
129. On Patrol
• Typically, we want soldiers guarding things, patrolling
‣ Go to the next waypoint
‣ When you get there, go to the next in the series etc
• Still just an iterative improvement on previous
22
130. On Patrol
• Typically, we want soldiers guarding things, patrolling
‣ Go to the next waypoint
‣ When you get there, go to the next in the series etc
• Still just an iterative improvement on previous
‣ We need to track where the waypoints are
22
131. On Patrol
• Typically, we want soldiers guarding things, patrolling
‣ Go to the next waypoint
‣ When you get there, go to the next in the series etc
• Still just an iterative improvement on previous
‣ We need to track where the waypoints are
‣ Which one we are near
22
132. On Patrol
• Typically, we want soldiers guarding things, patrolling
‣ Go to the next waypoint
‣ When you get there, go to the next in the series etc
• Still just an iterative improvement on previous
‣ We need to track where the waypoints are
‣ Which one we are near
‣ Which comes next in a sequence
22
137. Looking (Kinda) Smart
• An NPC that does just one thing is not smart
• Raging gun battle, it doesn’t make sense to carry on
patrolling.
24
138. Looking (Kinda) Smart
• An NPC that does just one thing is not smart
• Raging gun battle, it doesn’t make sense to carry on
patrolling.
• We’ve got now three different sets of code for
specific jobs, no way to swap between them.
24
140. Different Situations,
Different Behaviours
• So we know that different situations are going to
call for different behaviours
25
141. Different Situations,
Different Behaviours
• So we know that different situations are going to
call for different behaviours
• We need to be able to swap from one to another
realistically
25
142. Different Situations,
Different Behaviours
• So we know that different situations are going to
call for different behaviours
• We need to be able to swap from one to another
realistically
• This is where we’re going to really be using AI
techniques
25
144. Finite State Machines
• FSMs are fundamental building blocks in Computer
Science
26
145. Finite State Machines
• FSMs are fundamental building blocks in Computer
Science
• A machine that can be in one of a number of states
26
146. Finite State Machines
• FSMs are fundamental building blocks in Computer
Science
• A machine that can be in one of a number of states
• It transitions from one state to another when
certain conditions are met
26
149. NPCs as an FSM
• We can represent what behaviour is currently active
as a state in an FSM
28
150. NPCs as an FSM
• We can represent what behaviour is currently active
as a state in an FSM
• When certain things happen we can transition to a
different state
28
151. NPCs as an FSM
• We can represent what behaviour is currently active
as a state in an FSM
• When certain things happen we can transition to a
different state
• We can move around states as required
28
153. A Simple Guard
• Let’s combine what we’ve seen already
29
154. A Simple Guard
• Let’s combine what we’ve seen already
‣ A guard stands idle
29
155. A Simple Guard
• Let’s combine what we’ve seen already
‣ A guard stands idle
‣ When he sees the player he begins approaching
29
156. A Simple Guard
• Let’s combine what we’ve seen already
‣ A guard stands idle
‣ When he sees the player he begins approaching
‣ If the player breaks line of sight, he returns to his start
position
29
160. Non-Boolean Transitions
• We can track non-boolean values and use these as
triggers for state transitions
31
161. Non-Boolean Transitions
• We can track non-boolean values and use these as
triggers for state transitions
• Just need to meet a boolean criteria e.g. X > 100
31
163. Suspicious Guard
• This time, the guard will grow suspicious the longer
the player stays in view.
32
164. Suspicious Guard
• This time, the guard will grow suspicious the longer
the player stays in view.
‣ When suspicion hits a threshold, the guard will
investigate
32
165. Suspicious Guard
• This time, the guard will grow suspicious the longer
the player stays in view.
‣ When suspicion hits a threshold, the guard will
investigate
‣ If the player breaks line of sight, guards suspicion begins
to lower, continues to investigate
32
166. Suspicious Guard
• This time, the guard will grow suspicious the longer
the player stays in view.
‣ When suspicion hits a threshold, the guard will
investigate
‣ If the player breaks line of sight, guards suspicion begins
to lower, continues to investigate
‣ When suspicion drops below a threshold, returns to start
32
170. Beyond FSMs
• Finite State Machines are easy to understand
34
171. Beyond FSMs
• Finite State Machines are easy to understand
• But they get complicated quickly
34
172. Beyond FSMs
• Finite State Machines are easy to understand
• But they get complicated quickly
‣ Particularly for behaviours that need to have multiple
components chained to them, and be interruptible
34
173. Beyond FSMs
• Finite State Machines are easy to understand
• But they get complicated quickly
‣ Particularly for behaviours that need to have multiple
components chained to them, and be interruptible
• They aren’t state of the art, but good to introduce
concepts
34
174. Beyond FSMs
• Finite State Machines are easy to understand
• But they get complicated quickly
‣ Particularly for behaviours that need to have multiple
components chained to them, and be interruptible
• They aren’t state of the art, but good to introduce
concepts
• Not widely used in industry now.
34
177. Hierarchical Concurrent
State Machines
• Recent addition to the AI developers arsenal
• Popular after successful use in Left 4 Dead
35
178. Hierarchical Concurrent
State Machines
• Recent addition to the AI developers arsenal
• Popular after successful use in Left 4 Dead
‣ Drove NPCs
35
179. Hierarchical Concurrent
State Machines
• Recent addition to the AI developers arsenal
• Popular after successful use in Left 4 Dead
‣ Drove NPCs
‣ Also drove the AI Director system
35
180. Hierarchical Concurrent
State Machines
• Recent addition to the AI developers arsenal
• Popular after successful use in Left 4 Dead
‣ Drove NPCs
‣ Also drove the AI Director system
• A real-time parallel redesign of the Finite State
Machine (sort of)
35
183. Hierarchical Concurrent
State Machines
• Building block of an HCSM is itself an HCSM
‣ Recursive by nature
36
184. Hierarchical Concurrent
State Machines
• Building block of an HCSM is itself an HCSM
‣ Recursive by nature
• Analogue input wire
36
185. Hierarchical Concurrent
State Machines
• Building block of an HCSM is itself an HCSM
‣ Recursive by nature
• Analogue input wire
• Configuration parameters
36
186. Hierarchical Concurrent
State Machines
• Building block of an HCSM is itself an HCSM
‣ Recursive by nature
• Analogue input wire
• Configuration parameters
• Output wire
36
189. Behaviour Trees
• Behaviour Trees are another great way of deciding
which of a bunch of behaviours should be activated
at a given time.
38
190. Behaviour Trees
• Behaviour Trees are another great way of deciding
which of a bunch of behaviours should be activated
at a given time.
• Lets you craft intricate behaviours, and combine
them relatively intelligently.
38
191. Behaviour Trees
• Behaviour Trees are another great way of deciding
which of a bunch of behaviours should be activated
at a given time.
• Lets you craft intricate behaviours, and combine
them relatively intelligently.
• Kind of similar conceptually to a Decision Tree with
an internal knowledge of what triggered last time
38
192. Example Behaviour Tree
“Introduction to Behaviour Trees”, Bjoern Knafla
AltDevBlogADay.com
39
194. Path Finding
• Being able to automatically work out how to move
around a world is a common AI problem
40
195. Path Finding
• Being able to automatically work out how to move
around a world is a common AI problem
• Several good algorithms for doing this, today going
to show A*
40
196. Path Finding
• Being able to automatically work out how to move
around a world is a common AI problem
• Several good algorithms for doing this, today going
to show A*
• Works by assessing
40
197. Path Finding
• Being able to automatically work out how to move
around a world is a common AI problem
• Several good algorithms for doing this, today going
to show A*
• Works by assessing
‣ Work done
40
198. Path Finding
• Being able to automatically work out how to move
around a world is a common AI problem
• Several good algorithms for doing this, today going
to show A*
• Works by assessing
‣ Work done
‣ Estimating work remaining (a heuristic)
40
199. Path Finding
• Being able to automatically work out how to move
around a world is a common AI problem
• Several good algorithms for doing this, today going
to show A*
• Works by assessing
‣ Work done
‣ Estimating work remaining (a heuristic)
• Always selects most promising node
40
228. Pathfinding in Unity
• Unity 3.5 now includes pathfinding natively
‣ Pro only apparently
67
229. Pathfinding in Unity
• Unity 3.5 now includes pathfinding natively
‣ Pro only apparently
• Not entirely sure how this is implemented
67
230. Pathfinding in Unity
• Unity 3.5 now includes pathfinding natively
‣ Pro only apparently
• Not entirely sure how this is implemented
‣ I still haven’t bought Pro...
67
231. Pathfinding in Unity
• Unity 3.5 now includes pathfinding natively
‣ Pro only apparently
• Not entirely sure how this is implemented
‣ I still haven’t bought Pro...
• Possibly similar to the Path package (creator of that
works at Unity)
67
235. Runtime Woes
• We’ve talked about pathfinding and decision making
69
236. Runtime Woes
• We’ve talked about pathfinding and decision making
• These can be computationally hard problems
69
237. Runtime Woes
• We’ve talked about pathfinding and decision making
• These can be computationally hard problems
‣ In general we want to shoot for around 60fps
69
238. Runtime Woes
• We’ve talked about pathfinding and decision making
• These can be computationally hard problems
‣ In general we want to shoot for around 60fps
‣ 16.67ms of computation per frame
69
239. Runtime Woes
• We’ve talked about pathfinding and decision making
• These can be computationally hard problems
‣ In general we want to shoot for around 60fps
‣ 16.67ms of computation per frame
‣ Most of that will go on non-AI aspects
69
240. Runtime Woes
• We’ve talked about pathfinding and decision making
• These can be computationally hard problems
‣ In general we want to shoot for around 60fps
‣ 16.67ms of computation per frame
‣ Most of that will go on non-AI aspects
• Realistically looking at 1 or 2ms per frame for all AI
69
241. Runtime Woes
• We’ve talked about pathfinding and decision making
• These can be computationally hard problems
‣ In general we want to shoot for around 60fps
‣ 16.67ms of computation per frame
‣ Most of that will go on non-AI aspects
• Realistically looking at 1 or 2ms per frame for all AI
• Lots of computation, not a lot of time
69
243. Breaking Problems Up
• So we know that we might want to do things take
longer than we have.
70
244. Breaking Problems Up
• So we know that we might want to do things take
longer than we have.
• How can we break it up into manageable chunks so
that we aren’t delaying the game thread?
70
245. Breaking Problems Up
• So we know that we might want to do things take
longer than we have.
• How can we break it up into manageable chunks so
that we aren’t delaying the game thread?
• In Unity, we have a very powerful system at our
disposal called
70
246. Breaking Problems Up
• So we know that we might want to do things take
longer than we have.
• How can we break it up into manageable chunks so
that we aren’t delaying the game thread?
• In Unity, we have a very powerful system at our
disposal called
‣ Coroutines
70
248. Coroutines
• Coroutines are blocks of code that can return a
value partway through execution.
71
249. Coroutines
• Coroutines are blocks of code that can return a
value partway through execution.
• Next time that routine is called, it will pick up
where it left off
71
250. Coroutines
• Coroutines are blocks of code that can return a
value partway through execution.
• Next time that routine is called, it will pick up
where it left off
• Allows you to chop a block of code up into roughly
frame-computable chunks.
71
251. Coroutines
• Coroutines are blocks of code that can return a
value partway through execution.
• Next time that routine is called, it will pick up
where it left off
• Allows you to chop a block of code up into roughly
frame-computable chunks.
‣ Delays overall result, doesn’t delay code execution
71
253. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
72
254. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
- Lots of things in Unity are “delayed calls”
72
255. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
- Lots of things in Unity are “delayed calls”
• They don’t actually happen til the end of the frame
72
256. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
- Lots of things in Unity are “delayed calls”
• They don’t actually happen til the end of the frame
- Destroy(), Debug.Log()
72
257. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
- Lots of things in Unity are “delayed calls”
• They don’t actually happen til the end of the frame
- Destroy(), Debug.Log()
• We can do things like
72
258. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
- Lots of things in Unity are “delayed calls”
• They don’t actually happen til the end of the frame
- Destroy(), Debug.Log()
• We can do things like
yield return new WaitForEndOfFrame();
72
259. Juggling Timings
• Another great use of Coroutines is to get timing of
things right.
- Lots of things in Unity are “delayed calls”
• They don’t actually happen til the end of the frame
- Destroy(), Debug.Log()
• We can do things like
yield return new WaitForEndOfFrame();
• What we are waiting for happens, code resumes
72
263. Summary
• Today we covered basics/fundamentals
74
264. Summary
• Today we covered basics/fundamentals
‣ What we’re trying to achieve with Game AI
74
265. Summary
• Today we covered basics/fundamentals
‣ What we’re trying to achieve with Game AI
‣ Some very simple implementations of behaviours
74
266. Summary
• Today we covered basics/fundamentals
‣ What we’re trying to achieve with Game AI
‣ Some very simple implementations of behaviours
‣ Simple methods for selecting which is active
74
267. Summary
• Today we covered basics/fundamentals
‣ What we’re trying to achieve with Game AI
‣ Some very simple implementations of behaviours
‣ Simple methods for selecting which is active
‣ Discussion of some more advanced methods
74
268. Summary
• Today we covered basics/fundamentals
‣ What we’re trying to achieve with Game AI
‣ Some very simple implementations of behaviours
‣ Simple methods for selecting which is active
‣ Discussion of some more advanced methods
‣ Intro to Pathfinding
74
269. Summary
• Today we covered basics/fundamentals
‣ What we’re trying to achieve with Game AI
‣ Some very simple implementations of behaviours
‣ Simple methods for selecting which is active
‣ Discussion of some more advanced methods
‣ Intro to Pathfinding
‣ Coroutines for AI
74
275. But Wait There’s More!
• We haven’t scratched the surface of what we can do
with AI.
76
276. But Wait There’s More!
• We haven’t scratched the surface of what we can do
with AI.
‣ AI for companions
76
277. But Wait There’s More!
• We haven’t scratched the surface of what we can do
with AI.
‣ AI for companions
‣ AI for squad behaviours & coordination of multiple NPCs
76
278. But Wait There’s More!
• We haven’t scratched the surface of what we can do
with AI.
‣ AI for companions
‣ AI for squad behaviours & coordination of multiple NPCs
‣ AI for scenario control (e.g. Left 4 Dead)
76
279. But Wait There’s More!
• We haven’t scratched the surface of what we can do
with AI.
‣ AI for companions
‣ AI for squad behaviours & coordination of multiple NPCs
‣ AI for scenario control (e.g. Left 4 Dead)
‣ AI for content generation
76
280. Contact
• luke@cis.strath.ac.uk
• @LukeD
• http://saig.cis.strath.ac.uk - Research Group
• http://lukedicken.com - Personal Site
Questions?
77