Skip to content

Commit 884c8f5

Browse files
author
Marwan Mattar
authored
Merge pull request #483 from Unity-Technologies/docs/new-environment-refinements
Corrections and other refinements to the Creating a New Environment tutorial
2 parents ed304c7 + 8babee0 commit 884c8f5

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

docs/Learning-Environment-Create-New.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Next, we will create a very simple scene to act as our ML-Agents environment. Th
5757
2. Name the GameObject "Target"
5858
3. Select Target to view its properties in the Inspector window.
5959
4. Set Transform to Position = (3,0.5,3), Rotation = (0,0,0), Scale = (1,1,1).
60-
5. On the Cube's Mesh Renderer, expand the Materials property and change the default-material to *block*.
60+
5. On the Cube's Mesh Renderer, expand the Materials property and change the default-material to *Block*.
6161

6262
![The Target Cube in the Inspector window](images/mlagents-NewTutBlock.png)
6363

@@ -114,15 +114,13 @@ The default settings for the Academy properties are also fine for this environme
114114

115115
## Add a Brain
116116

117-
The Brain object encapsulates the decision making process. An Agent sends its observations to its Brain and expects a decision in return. The Brain Type setting determines how the Brain makes decisions. Unlike the Academy and Agent classes, you don't make your own Brain subclasses. (You can extend CoreBrain to make your own *types* of Brain, but the four built-in brain types should cover almost all scenarios.)
117+
The Brain object encapsulates the decision making process. An Agent sends its observations to its Brain and expects a decision in return. The Brain Type setting determines how the Brain makes decisions. Unlike the Academy and Agent classes, you don't make your own Brain subclasses.
118118

119119
To create the Brain:
120120

121-
1. Right-click the Academy GameObject in the Hierarchy window and choose *Create Empty* to add a child GameObject.
122-
2. Name the new GameObject, "Brain".
123-
3. Select the Brain GameObject to show its properties in the Inspector window.
124-
4. Click **Add Component**.
125-
5. Select the **Scripts/Brain** component to add it to the GameObject.
121+
1. Select the Brain GameObject created earlier to show its properties in the Inspector window.
122+
2. Click **Add Component**.
123+
3. Select the **Scripts/Brain** component to add it to the GameObject.
126124

127125
We will come back to the Brain properties later, but leave the Brain Type as **Player** for now.
128126

@@ -221,7 +219,6 @@ All the values are divided by 5 to normalize the inputs to the neural network to
221219

222220
In total, the state observation contains 8 values and we need to use the continuous state space when we get around to setting the Brain properties:
223221

224-
List<float> observation = new List<float>();
225222
public override void CollectObservations()
226223
{
227224
@@ -247,12 +244,9 @@ The final part of the Agent code is the Agent.AgentAction() function, which rece
247244

248245
**Actions**
249246

250-
The decision of the Brain comes in the form of an action array passed to the `AgentAction()` function. The number of elements in this array is determined by the `Vector Action Space Type` and `Vector Action Space Size` settings of the agent's Brain. The RollerAgent uses the continuous vector action space and needs two continuous control signals from the brain. Thus, we will set the Brain `Vector Action Size` to 2. The first element,`action[0]` determines the force applied along the x axis; `action[1]` determines the force applied along the z axis. (If we allowed the agent to move in three dimensions, then we would need to set `Vector Action Size` to 3. Note the Brain really has no idea what the values in the action array mean. The training process adjust the action values in response to the observation input and then sees what kind of rewards it gets as a result.
251-
252-
Before we can add a force to the agent, we need a reference to its Rigidbody component. A [Rigidbody](https://docs.unity3d.com/ScriptReference/Rigidbody.html) is Unity's primary element for physics simulation. (See [Physics](https://docs.unity3d.com/Manual/PhysicsSection.html) for full documentation of Unity physics.) A good place to set references to other components of the same GameObject is in the standard Unity `Start()` method:
247+
The decision of the Brain comes in the form of an action array passed to the `AgentAction()` function. The number of elements in this array is determined by the `Vector Action Space Type` and `Vector Action Space Size` settings of the agent's Brain. The RollerAgent uses the continuous vector action space and needs two continuous control signals from the brain. Thus, we will set the Brain `Vector Action Size` to 2. The first element,`action[0]` determines the force applied along the x axis; `action[1]` determines the force applied along the z axis. (If we allowed the agent to move in three dimensions, then we would need to set `Vector Action Size` to 3. Note the Brain really has no idea what the values in the action array mean. The training process just adjusts the action values in response to the observation input and then sees what kind of rewards it gets as a result.
253248

254-
255-
With the reference to the Rigidbody, the agent can apply the values from the action[] array using the `Rigidbody.AddForce` function:
249+
The RollerAgent applies the values from the action[] array to its Rigidbody component, `rBody`, using the `Rigidbody.AddForce` function:
256250

257251
Vector3 controlSignal = Vector3.zero;
258252
controlSignal.x = Mathf.Clamp(action[0], -1, 1);
@@ -360,10 +354,10 @@ Also, drag the Target GameObject from the Hierarchy window to the RollerAgent Ta
360354

361355
Finally, select the Brain GameObject so that you can see its properties in the Inspector window. Set the following properties:
362356

357+
* `Vector Observation Space Type` = **Continuous**
363358
* `Vector Observation Space Size` = 8
364-
* `Vector Action Space Size` = 2
365359
* `Vector Action Space Type` = **Continuous**
366-
* `Vector Observation Space Type` = **Continuous**
360+
* `Vector Action Space Size` = 2
367361
* `Brain Type` = **Player**
368362

369363
Now you are ready to test the environment before training.

0 commit comments

Comments
 (0)