Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
quick:agents [2020/02/20 11:26]
jesusmayoral [Setting-Up the execution with Behavior Bricks]
quick:agents [2020/09/03 11:46] (current)
pedro
Line 1: Line 1:
 +<markdown>
 # ML-Agents Integration Guide # ML-Agents Integration Guide
  
Line 16: Line 17:
 - Add a cube to the enemy above the `shootpoint` scaled to (0.1, 0.1, 0.3) at the relative position (0, 0.5, 0.5). This will tell us where the enemy is aiming. - Add a cube to the enemy above the `shootpoint` scaled to (0.1, 0.1, 0.3) at the relative position (0, 0.5, 0.5). This will tell us where the enemy is aiming.
  
-{{:images:agents:Enemy_Aim_adapted.png}}+![](:images:agents:Enemy_Aim_adapted.png)
  
 In addition, we have to modify the way the enemy shoots in order to fit the training and the execution of the agent. Specifically, we create two new C# scripts: `FiredBullet` and `EnemyShoot`. In addition, we have to modify the way the enemy shoots in order to fit the training and the execution of the agent. Specifically, we create two new C# scripts: `FiredBullet` and `EnemyShoot`.
Line 22: Line 23:
 The script `FiredBullet` consists in giving intelligence to the bullet, so it can tell if the it has impacted the player, besides autodestroy passed 2 seconds (or whatever the time indicated by the parameter). Additionally, the bullet has information about its creator, which will be used for knowing who to inform of the impact. Therefore, we have to add the following C# script to the Bullet prefab, after removing the script used in previous tutorials. The script `FiredBullet` consists in giving intelligence to the bullet, so it can tell if the it has impacted the player, besides autodestroy passed 2 seconds (or whatever the time indicated by the parameter). Additionally, the bullet has information about its creator, which will be used for knowing who to inform of the impact. Therefore, we have to add the following C# script to the Bullet prefab, after removing the script used in previous tutorials.
  
-<code csharp>+ 
 +```csharp
  using UnityEngine;  using UnityEngine;
  
Line 61: Line 63:
      }      }
  }  }
-</code>+```
  
 The code should be self-explanatory, but we have to note several things: The code should be self-explanatory, but we have to note several things:
Line 71: Line 73:
 The script `EnemyShoot` implements the shooting capacity of the enemy agent. We create a C# script that extends `Monobehaviour` based on the previous script `ShootOnce`.  This code should be self-explanatory too, and have to be added to the enemy, binding the shootpoint and the bullet prefab in the editor. The script `EnemyShoot` implements the shooting capacity of the enemy agent. We create a C# script that extends `Monobehaviour` based on the previous script `ShootOnce`.  This code should be self-explanatory too, and have to be added to the enemy, binding the shootpoint and the bullet prefab in the editor.
  
-<code csharp>+```csharp
  using UnityEngine;  using UnityEngine;
  
Line 148: Line 150:
      }      }
  }  }
-</code>+```
  
 We have to note the following points: We have to note the following points:
Line 159: Line 161:
 Finally, we create the C# script `EnemyAgent`, extending `Agent` class of `MLAgents`.  We add the following code, deleting the code included by default (`Start` and `Update` methods). Finally, we create the C# script `EnemyAgent`, extending `Agent` class of `MLAgents`.  We add the following code, deleting the code included by default (`Start` and `Update` methods).
  
-<code csharp>+```csharp
  using UnityEngine;  using UnityEngine;
  
Line 252: Line 254:
      }      }
  }  }
-</code>+```
  
 This class has three main methods that are overriden from the `Agent` class. Explaining why this methods have to be overridden and how Agent class works is out of the scope of this guide. The concrete implementation of these methods is described below. This class has three main methods that are overriden from the `Agent` class. Explaining why this methods have to be overridden and how Agent class works is out of the scope of this guide. The concrete implementation of these methods is described below.
Line 274: Line 276:
  
  
-{{:images:agents:arbol1editadov2.png}}+![](:images:agents:arbol1editadov2.png)
  
  
Line 283: Line 285:
  
  
-{{:images:agents:arbol2editado.png}}+![](:images:agents:arbol2editado.png)
  
  
Line 291: Line 293:
  
  
-{{:images:agents:enemytreeeditado.png}}+![](:images:agents:enemytreeeditado.png)
  
  
Line 302: Line 304:
  
  
-{{:images:agents:behaviorexecutorv1.4.png}}+![](:images:agents:behaviorexecutorv1.4.png)
  
  
Line 308: Line 310:
  
  
-{{:images:agents:behaviorparamswithouttrainedmodel.png}}+![](:images:agents:behaviorparamswithouttrainedmodel.png)
  
  
Line 321: Line 323:
  
  
-{{:images:agents:BehaviorParams.png}}+![](:images:agents:BehaviorParams.png)
  
  
Line 327: Line 329:
  
 The node used to execute `ML-Agents` in `Behavior Bricks` lets also to train a behavior inside a behavior tree. To do so, We have to follow the same procedure as indicated in [ML-Agents guides.](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Training-ML-Agents.md) The node used to execute `ML-Agents` in `Behavior Bricks` lets also to train a behavior inside a behavior tree. To do so, We have to follow the same procedure as indicated in [ML-Agents guides.](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Training-ML-Agents.md)
 +
 +</markdown>