public override void AgentAction(float[] vectorAction, string textAction) { Vector3 BallTransform = Ball.transform.position; var actionZ = 0.1f * Mathf.Clamp(vectorAction[0], -1f, 1f); var actionX = 0.1f * Mathf.Clamp(vectorAction[1], -1f, 1f); if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) || (gameObject.transform.rotation.z > -0.25f && actionZ < 0f)) { gameObject.transform.Rotate(new Vector3(0, 0, 1), actionZ); } if ((gameObject.transform.rotation.x < 0.25f && actionX > 0f) || (gameObject.transform.rotation.x > -0.25f && actionX < 0f)) { gameObject.transform.Rotate(new Vector3(1, 0, 0), actionX); } float distanceToTarget = Vector3.Distance(Ball.transform.position, Target.position); if (distanceToTarget < 0.5f) { SetReward(0.0f); Done(); } else if (BallTransform.y - gameObject.transform.position.y < -2f || Mathf.Abs(BallTransform.x - gameObject.transform.position.x) > 2.5f || Mathf.Abs(BallTransform.z - gameObject.transform.position.z) > 2.5f) { SetReward(-11.0f); Done(); } else { bool found = false; for (int i = 0; i < this.transform.childCount; i++) { if (this.transform.GetChild(i).gameObject.tag == "wall") { script = this.transform.GetChild(i).gameObject.GetComponent <colider> (); if (script.stat == true) { SetReward(-11.0f); found = true; script.stat = false; } } } if (found == false) { SetReward(-10.0f); } } }
public override void AgentAction(float[] vectorAction, string textAction) { integrator = new Vector3(0.0f, 0.0f, 0.0f); Vector3 BallTransform = Ball.transform.position; // desired rotation actionX = vectorAction[0]; actionZ = vectorAction[1]; float distanceToTarget = Vector3.Distance(Ball.transform.position, Goal.transform.position); if (distanceToTarget < 0.005f) { SetReward(0.0f); Done(); } else if (BallTransform.y - gameObject.transform.position.y < -2f || Mathf.Abs(BallTransform.x - gameObject.transform.position.x) > 0.335f || Mathf.Abs(BallTransform.z - gameObject.transform.position.z) > 0.335f) { SetReward(-11.0f); Done(); } else { bool found = false; for (int i = 0; i < this.transform.childCount; i++) { if (this.transform.GetChild(i).gameObject.tag == "wall") { script = this.transform.GetChild(i).gameObject.GetComponent <colider> (); if (script.stat == true) { SetReward(-11.0f); found = true; script.stat = false; } } } if (found == false) { SetReward(-1.0f); } } }
public override void AgentAction(float[] vectorAction, string textAction) { Vector3 BallTransform = Ball.transform.position; bool baseLeft = false; bool goalTouch = false; bool wallTouch = false; var actionZ = Mathf.Clamp(vectorAction[0], -1f, 1f); var actionX = Mathf.Clamp(vectorAction[1], -1f, 1f); if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) || (gameObject.transform.rotation.z > -0.25f && actionZ < 0f)) { gameObject.transform.Rotate(new Vector3(0, 0, 1), actionZ); gameObject.transform.Rotate(new Vector3(0, 1, 1), 0.0f); } if ((gameObject.transform.rotation.x < 0.25f && actionX > 0f) || (gameObject.transform.rotation.x > -0.25f && actionX < 0f)) { gameObject.transform.Rotate(new Vector3(1, 0, 0), actionX); gameObject.transform.Rotate(new Vector3(0, 1, 0), 0.0f); } float distanceToTarget = Vector3.Distance(Ball.transform.position, Target.position); if (BallTransform.y - gameObject.transform.position.y < -2f || Mathf.Abs(BallTransform.x - gameObject.transform.position.x) > 2.5f || Mathf.Abs(BallTransform.z - gameObject.transform.position.z) > 2.5f) { SetReward(-11.0f); Done(); } else { for (int i = 0; i < this.transform.childCount; i++) { if (this.transform.GetChild(i).gameObject.tag == "wall") { script = this.transform.GetChild(i).gameObject.GetComponent <colider> (); if (script.stat == true) { //wallTouch = true; script.stat = false; } } if (this.transform.GetChild(i).gameObject.tag == "Base") { script = this.transform.GetChild(i).gameObject.GetComponent <colider> (); if (script.stat == false) { baseLeft = true; } else { script.stat = false; } } if (this.transform.GetChild(i).gameObject.tag == "Goal") { script = this.transform.GetChild(i).gameObject.GetComponent <colider> (); if (script.stat == true) { goalTouch = true; script.stat = false; } } } if (goalTouch == true || Vector3.Distance(Ball.transform.position, Target.position) < 0.5f) { Done(); SetReward(0.0f); } else if (baseLeft == true) { Done(); SetReward(-10.0f); } else if (wallTouch == true) { SetReward(-10.0f); } else if (Vector3.Distance(Ball2, Ball1) > Vector3.Distance(Ball2, Ball.transform.position)) { SetReward(-10.0f); } else { SetReward(-1.0f); } } Ball2 = Ball1; Ball1 = Ball.transform.position; }
void OntriggerEnter(colider other) { Destroy(Player); }