Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the tennis Agent. Works with prefab now #1343

Merged
merged 2 commits into from Oct 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
Expand Up @@ -10,20 +10,34 @@ public class TennisAgent : Agent
public GameObject ball;
public bool invertX;
public int score;
public GameObject scoreText;
public GameObject myArea;
public GameObject opponent;

private Text textComponent;
private Rigidbody agentRb;
private Rigidbody ballRb;
private float invertMult;

// Looks for the scoreboard based on the name of the gameObjects.
// Do not modify the names of the Score GameObjects
private const string CanvasName = "Canvas";
private const string ScoreBoardAName = "ScoreA";
private const string ScoreBoardBName = "ScoreB";

public override void InitializeAgent()
{
agentRb = GetComponent<Rigidbody>();
ballRb = GetComponent<Rigidbody>();
textComponent = scoreText.GetComponent<Text>();
var canvas = GameObject.Find(CanvasName);
GameObject scoreBoard;
if (invertX)
{
scoreBoard = canvas.transform.Find(ScoreBoardBName).gameObject;
}
else
{
scoreBoard = canvas.transform.Find(ScoreBoardAName).gameObject;
}
textComponent = scoreBoard.GetComponent<Text>();
}

public override void CollectObservations()
Expand Down