|
|
|
|
|
|
public bool invertX; |
|
|
|
public int score; |
|
|
|
public GameObject myArea; |
|
|
|
public float angle; |
|
|
|
public float scale; |
|
|
|
private ResetParameters resetParams; |
|
|
|
|
|
|
|
// Looks for the scoreboard based on the name of the gameObjects.
|
|
|
|
// Do not modify the names of the Score GameObjects
|
|
|
|
|
|
|
ballRb = ball.GetComponent<Rigidbody>(); |
|
|
|
var canvas = GameObject.Find(CanvasName); |
|
|
|
GameObject scoreBoard; |
|
|
|
var academy = Object.FindObjectOfType<Academy>() as Academy; |
|
|
|
resetParams = academy.resetParameters; |
|
|
|
if (invertX) |
|
|
|
{ |
|
|
|
scoreBoard = canvas.transform.Find(ScoreBoardBName).gameObject; |
|
|
|
|
|
|
scoreBoard = canvas.transform.Find(ScoreBoardAName).gameObject; |
|
|
|
} |
|
|
|
textComponent = scoreBoard.GetComponent<Text>(); |
|
|
|
SetResetParameters(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void CollectObservations() |
|
|
|
|
|
|
{ |
|
|
|
var moveX = Mathf.Clamp(vectorAction[0], -1f, 1f) * invertMult; |
|
|
|
var moveY = Mathf.Clamp(vectorAction[1], -1f, 1f); |
|
|
|
|
|
|
|
|
|
|
|
if (moveY > 0.5 && transform.position.y - transform.parent.transform.position.y < -1.5f) |
|
|
|
{ |
|
|
|
agentRb.velocity = new Vector3(agentRb.velocity.x, 7f, 0f); |
|
|
|
|
|
|
|
|
|
|
if (invertX && transform.position.x - transform.parent.transform.position.x < -invertMult || |
|
|
|
if (invertX && transform.position.x - transform.parent.transform.position.x < -invertMult || |
|
|
|
transform.position = new Vector3(-invertMult + transform.parent.transform.position.x, |
|
|
|
transform.position.y, |
|
|
|
transform.position.z); |
|
|
|
transform.position = new Vector3(-invertMult + transform.parent.transform.position.x, |
|
|
|
transform.position.y, |
|
|
|
transform.position.z); |
|
|
|
} |
|
|
|
|
|
|
|
textComponent.text = score.ToString(); |
|
|
|
|
|
|
|
|
|
|
transform.position = new Vector3(-invertMult * Random.Range(6f, 8f), -1.5f, 0f) + transform.parent.transform.position; |
|
|
|
agentRb.velocity = new Vector3(0f, 0f, 0f); |
|
|
|
|
|
|
|
SetResetParameters(); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetRacket() |
|
|
|
{ |
|
|
|
angle = resetParams["angle"]; |
|
|
|
gameObject.transform.eulerAngles = new Vector3( |
|
|
|
gameObject.transform.eulerAngles.x, |
|
|
|
gameObject.transform.eulerAngles.y, |
|
|
|
invertMult * angle |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetBall() |
|
|
|
{ |
|
|
|
scale = resetParams["scale"]; |
|
|
|
ball.transform.localScale = new Vector3(scale, scale, scale); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetResetParameters() |
|
|
|
{ |
|
|
|
SetRacket(); |
|
|
|
SetBall(); |
|
|
|
} |
|
|
|
} |