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
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.
Hi @Porigon45
Thank you for bringing this to our attention. Would you be willing to submit a pull request with this change in it? If not, I can take a look at making the change myself.
Thank you for your reply but I can't find out how to pull request. Could you please do that?
No worries. I can definitely take care of it. Thanks again for bringing it to our attention!
Most helpful comment
No worries. I can definitely take care of it. Thanks again for bringing it to our attention!