SlideShare a Scribd company logo
2
Привет!
My name is Ciro Continisio
Technical Evangelist at Unity
3
Привет!
My name is Alessia Nigretti
Technical Evangelist at Unity
4
Machine
Learning in Unity
5
Introduction
What is Machine Learning?
6
What is Machine Learning
7
What is Machine Learning
Reinforcement Learning
8
A computer system
modelled on
the human brain and
nervous system
Neural Networks
What is Machine Learning
9
Machine Learning
Agents
10
Reinforcement Learning
11
Learning Environments
12
Learning Environments
13
Learning Environments
14
Example Projects
15
3D Ball
Goal:
Balance the ball on the platform
Reward:
● +0.1 for every frame the ball
remains on the platform
● -1.0 if the ball falls from the
platform
16
Propellers
Goal:
Have the cubes learn to float
Reward:
● +0.1 for each frame the cube floats
● -1.0 for each collision with the floor
17
Arena
Goal:
Push the crate out of the arena
Rewards:
● +0.2 for if closing on the crate
● +0.5 when crates gets further from
the center
● Neg. rewards for delaying, or falling
18
Bounce Ball
Goal:
Bounce ball on top of agent’s head
Reward:
● +0.1 for each frame the ball is
closer to the agent
● -0.1 for each frame the ball is
further away from the agent
19
Problem
Can you use Machine Learning
in a real game?
20
Roguelike
21
Roguelike Game
Ingredients
• A simple action game
• All entities are Agents, both the player and the enemies
• Establish a common “interaction language”
• The goal is survival, while attacking other entities
22
Setting up the training
23
Setting up the training
Design and
ideas
• What are the game actions
• What you want the Agent
to learn
• What’s right or wrong
(what to reward)
24
Discrete vs. Continuous
Discrete means that the States/Actions can only have one value
at a time. Like an Enum. It’s either 0, or 1, or 2, or 3, etc.
⬝ Easier: Agents associate actions with rewards more easily
In Roguelike, we use Discrete for Actions. It can have 6 values:
0: Stay still / 1-4: Move in one direction / 5: Attack
Setting up the training
25
Discrete vs. Continuous
Continuous means you can have multiple States (or Actions)
and they all have float values.
⬝ They require more memory for training (hyperparameters)
⬝ Hard to use: they can confuse the Agent
In Roguelike, we use Continuous for States:
health, canAttack, hasTarget, distanceFromTarget, …
Setting up the training
26
Setting up the training
The pseudo-algorithm (AgentStep)
If health > 50% then
If current distance < previous distance then
Reward
End
Else
If current distance > previous distance then
Reward
End
End
If input is attack
If can attack then
Start attack
Else
Punish
Else
If is not healing and health < max health then
Start healing
End
End
Movement Attack
27
Spoiler
This initial algorithm has changed
a lot
28
Tips on rewards
• Rewards can come in the AgentStep function, but also at
other times (OnCollisionEnter, etc.)
• Agents will find a way to exploit the rewards!
• Small details in rewards influence the learning process
Setting up the training
reward = .2f / (distanceSqr + .01f); > reward = .2f;
29
Training scene
• Position and configure the
agent(s)
• Connect them to the
relevant Brains
• Configure the Academy
Setting up the training
30
Demo time!
31
Tips for the training environment
• Different situations in parallel help Agents to learn better
• Heuristic Agents are the perfect training dummies!
• Before launching a 1 hour training:
• Double-check your logic so you don’t make wrong
assumptions
• Launch a 1x speed training to see what’s happening
Setting up the training
32
Building and training
• Set the Brain to External
• Build!
• Set up python environment and hyperparameters
• Launch training
Training
33
Demo time!
34
Training with Tensorflow
• Observe the mean reward
• Stop when it looks stable
• Export the model, import into Unity
• Set the Brain to Internal
• Play!
Training
35
Demo time!
36
Final tips and
Key takeaways
37
Tips on hyperparameters
• Beta: is the randomisation of actions. If agents corner
themselves on a behaviour quickly, increase beta
• Batch size, Buffer size, Hidden units: they differ a lot
between using Discrete or Continuous spaces
Read the guide: github.com/Unity-Technologies/ml-agents
Training
38
Tips and takeaways
Physics
Because ML runs on the FixedUpdate (for stability):
• Remember Rigidbody.position doesn’t change mid-frame
• Switch Animators from Normal to Animate Physics if
animation is key in the training
• If using interpolation on the RB, Rigidbody.position or
Rigidbody.MovePosition( ) behave differently
39
Tips and takeaways
Build tools
The training process can be
long and repetitive.
Make your life easier by
building some little tools.
40
One last demo!
41
Next
What now?
• Mix Trained AI with Heuristic AI to obtain final behaviour
Learning from the player
• Gather players’ behaviour and train agents (offline)
based on the information you obtained
• Coming soon: Imitation Learning!
42
Спасибо!
Ciro Continisio
ciro@unity3d.com
@CiroContns
Alessia Nigretti
alessian@unity3d.com
@AlessiaNigretti
Get the demo and presentation:
bit.ly/UnityDevgammMinsk

More Related Content

Similar to Machine Learning in Unity - How to give your game AI a real brain

How to Allow Java Applets for physics labsWindows 7Ope.docx
How to Allow Java Applets for physics labsWindows 7Ope.docxHow to Allow Java Applets for physics labsWindows 7Ope.docx
How to Allow Java Applets for physics labsWindows 7Ope.docx
wellesleyterresa
 
Designing Games for Industrial Training.
Designing Games for Industrial Training.Designing Games for Industrial Training.
Designing Games for Industrial Training.
SeriousGamesAssoc
 
24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx
ManiMaran230751
 
Relay race lego nxt g
Relay race lego nxt gRelay race lego nxt g
Relay race lego nxt g
Jason Zagami
 

Similar to Machine Learning in Unity - How to give your game AI a real brain (20)

【Unite Tokyo 2018】Unity for ディープ・ラーニング:ツールキット『ML-Agents』のご紹介
【Unite Tokyo 2018】Unity for ディープ・ラーニング:ツールキット『ML-Agents』のご紹介【Unite Tokyo 2018】Unity for ディープ・ラーニング:ツールキット『ML-Agents』のご紹介
【Unite Tokyo 2018】Unity for ディープ・ラーニング:ツールキット『ML-Agents』のご紹介
 
How to Allow Java Applets for physics labsWindows 7Ope.docx
How to Allow Java Applets for physics labsWindows 7Ope.docxHow to Allow Java Applets for physics labsWindows 7Ope.docx
How to Allow Java Applets for physics labsWindows 7Ope.docx
 
OpenAI Gym & Universe
OpenAI Gym & UniverseOpenAI Gym & Universe
OpenAI Gym & Universe
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
 
Creative Engineering 101
Creative Engineering 101Creative Engineering 101
Creative Engineering 101
 
Intro to Reinforcement Learning
Intro to Reinforcement LearningIntro to Reinforcement Learning
Intro to Reinforcement Learning
 
Design Thinking + Lean + Agile
Design Thinking + Lean + AgileDesign Thinking + Lean + Agile
Design Thinking + Lean + Agile
 
Getting better
Getting betterGetting better
Getting better
 
Designing Games for Industrial Training.
Designing Games for Industrial Training.Designing Games for Industrial Training.
Designing Games for Industrial Training.
 
Leap from Doing Agile to Being Agile_AAC2019
Leap from Doing Agile to Being Agile_AAC2019Leap from Doing Agile to Being Agile_AAC2019
Leap from Doing Agile to Being Agile_AAC2019
 
Behavioral hypothesis of team behavior
Behavioral hypothesis of team behaviorBehavioral hypothesis of team behavior
Behavioral hypothesis of team behavior
 
BA and Beyond 19 - Pieter Van Driessche - The 7 hidden layers behind agile te...
BA and Beyond 19 - Pieter Van Driessche - The 7 hidden layers behind agile te...BA and Beyond 19 - Pieter Van Driessche - The 7 hidden layers behind agile te...
BA and Beyond 19 - Pieter Van Driessche - The 7 hidden layers behind agile te...
 
24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx24.09.2021 Reinforcement Learning Algorithms.pptx
24.09.2021 Reinforcement Learning Algorithms.pptx
 
Genetic Algorithms for Evolving Computer Chess Programs
Genetic Algorithms for Evolving Computer Chess Programs   Genetic Algorithms for Evolving Computer Chess Programs
Genetic Algorithms for Evolving Computer Chess Programs
 
Will Robots Replace Testers?
Will Robots Replace Testers?Will Robots Replace Testers?
Will Robots Replace Testers?
 
Game theory for a better world
Game theory for a better worldGame theory for a better world
Game theory for a better world
 
Building a deep learning ai.pptx
Building a deep learning ai.pptxBuilding a deep learning ai.pptx
Building a deep learning ai.pptx
 
Purple Team Exercise Workshop December 2020
Purple Team Exercise Workshop December 2020Purple Team Exercise Workshop December 2020
Purple Team Exercise Workshop December 2020
 
Briefly About Reinforcement Learning which we are using in our Esports project?
Briefly About Reinforcement Learning which we are using in our Esports project?Briefly About Reinforcement Learning which we are using in our Esports project?
Briefly About Reinforcement Learning which we are using in our Esports project?
 
Relay race lego nxt g
Relay race lego nxt gRelay race lego nxt g
Relay race lego nxt g
 

More from DevGAMM Conference

More from DevGAMM Conference (20)

The art of small steps, or how to make sound for games in conditions of war /...
The art of small steps, or how to make sound for games in conditions of war /...The art of small steps, or how to make sound for games in conditions of war /...
The art of small steps, or how to make sound for games in conditions of war /...
 
Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...
Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...
Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...
 
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
 
Why indie developers should consider hyper-casual right now / Igor Gurenyov (...
Why indie developers should consider hyper-casual right now / Igor Gurenyov (...Why indie developers should consider hyper-casual right now / Igor Gurenyov (...
Why indie developers should consider hyper-casual right now / Igor Gurenyov (...
 
AI / ML for Indies / Tyler Coleman (Retora Games)
AI / ML for Indies / Tyler Coleman (Retora Games)AI / ML for Indies / Tyler Coleman (Retora Games)
AI / ML for Indies / Tyler Coleman (Retora Games)
 
Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...
Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...
Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...
 
New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...
New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...
New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...
 
Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...
Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...
Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...
 
Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...
Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...
Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...
 
From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)
From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)
From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)
 
Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)
Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)
Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)
 
Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...
Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...
Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...
 
How to increase wishlists & game sales from China? Growth marketing tactics &...
How to increase wishlists & game sales from China? Growth marketing tactics &...How to increase wishlists & game sales from China? Growth marketing tactics &...
How to increase wishlists & game sales from China? Growth marketing tactics &...
 
Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)
Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)
Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)
 
Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...
Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...
Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...
 
Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...
Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...
Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...
 
The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...
The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...
The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...
 
Branded Content: How to overcome players' immunity to advertising / Alex Brod...
Branded Content: How to overcome players' immunity to advertising / Alex Brod...Branded Content: How to overcome players' immunity to advertising / Alex Brod...
Branded Content: How to overcome players' immunity to advertising / Alex Brod...
 
Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...
Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...
Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...
 
How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...
How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...
How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 

Machine Learning in Unity - How to give your game AI a real brain