Ml-agents: Small error in Tennis Examples

Created on 2 Apr 2020  路  3Comments  路  Source: Unity-Technologies/ml-agents

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.

bug

Most helpful comment

No worries. I can definitely take care of it. Thanks again for bringing it to our attention!

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DVonk picture DVonk  路  3Comments

GeriBP picture GeriBP  路  3Comments

scotthovestadt picture scotthovestadt  路  4Comments

gerardsimons picture gerardsimons  路  3Comments

DavidLining picture DavidLining  路  3Comments