Description
Hello,
I found a trivial misitake in tennis examples and I'm going to show how to fix the problem.
About the bug and Console logs
When you try to move the Agent (Heuristic mode), you will have an error like below
"IndexOutOfRangeException: Index was outside the bounds of the array.
TennisAgent.OnActionReceived (System.Single[] vectorAction) (at Assets/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs:70)"
To Slove
Go to 'TennisAgent.cs' on Line 91.
(The following code are from 63 to 96 from above script)
public override void OnActionReceived(float[] vectorAction)
{
var moveX = Mathf.Clamp(vectorAction[0], -1f, 1f) * m_InvertMult;
var moveY = Mathf.Clamp(vectorAction[1], -1f, 1f);
var rotate = Mathf.Clamp(vectorAction[2], -1f, 1f) * m_InvertMult;
...
}
public override float[] Heuristic()
{
var action = new float[2];
action[0] = Input.GetAxis("Horizontal");
action[1] = Input.GetKey(KeyCode.Space) ? 1f : 0f;
return action;
}
The number of elements in the array is different. (3 in OnActionReceived() but 2 in Heuristic() )
So, I think it's good to fix this code like below.
public override float[] Heuristic()
{
var action = new float[3];
action[0] = Input.GetAxis("Horizontal"); // Racket Movement
action[1] = Input.GetKey(KeyCode.Space) ? 1f : 0f; // Racket Jamping
action[2] = Input.GetAxis("Vertical"); // Racket Rotation
return action;
}
Although it's hard to controll the racket, now you will have no errors.
Environment
- OS + version: Windows 10
- ML-Agents version: ML-Agents v0.15.0
- Environment: Unity 2018.4.19f1
Cf. I'm a Japanese high school students, and I have difficulties not only in using Unity or ML-Agents but in writing English. I would very appreciate it if you reply in plain English.