|
|
|
|
|
|
[Header("Specific to Ball3D")] |
|
|
|
public GameObject ball; |
|
|
|
private Rigidbody ballRb; |
|
|
|
private ResetParameters resetParams; |
|
|
|
var academy = Object.FindObjectOfType<Academy>() as Academy; |
|
|
|
resetParams = academy.resetParameters; |
|
|
|
SetResetParameters(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void CollectObservations() |
|
|
|
|
|
|
|
|
|
|
public override void AgentAction(float[] vectorAction, string textAction) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (brain.brainParameters.vectorActionSpaceType == SpaceType.continuous) |
|
|
|
{ |
|
|
|
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f); |
|
|
|
|
|
|
ballRb.velocity = new Vector3(0f, 0f, 0f); |
|
|
|
ball.transform.position = new Vector3(Random.Range(-1.5f, 1.5f), 4f, Random.Range(-1.5f, 1.5f)) |
|
|
|
+ gameObject.transform.position; |
|
|
|
//Reset the parameters when the Agent is reset.
|
|
|
|
SetResetParameters(); |
|
|
|
} |
|
|
|
public void SetBall() |
|
|
|
{ |
|
|
|
//Set the attributes of the ball by fetching the information from the academy
|
|
|
|
ballRb.mass = resetParams["mass"]; |
|
|
|
var scale = resetParams["scale"]; |
|
|
|
ball.transform.localScale = new Vector3(scale, scale, scale); |
|
|
|
public void SetResetParameters() |
|
|
|
{ |
|
|
|
SetBall(); |
|
|
|
} |
|
|
|
} |