public override void AgentAction(float[] vectorAction, string textAction) { for (int i = 0; i < vectorAction.Length; i++) { rocketController.SetThrust(i, Mathf.Clamp(vectorAction[i], -1f, 1f) >= 0f); } Vector2 velDelta = goalVel - (new Vector2(rb.velocity.x, rb.velocity.y)); float deltaMag = velDelta.magnitude < 0.01f ? 0.01f : velDelta.magnitude; float rew = 1f / (deltaMag / goalVel.magnitude); rew /= 1000f; SetReward(rew); if (Mathf.Abs(goalVel.magnitude - (new Vector2(rb.velocity.x, rb.velocity.y)).magnitude) > 10f) { SetReward(-1f); Done(); } if (timeRun <= 0f) { Done(); } }
public override void AgentAction(float[] vectorAction, string textAction) { //if (brain.brainParameters.vectorActionSpaceType == SpaceType.discrete) //{ for (int i = 0; i < vectorAction.Length; i++) { rocketController.SetThrust(i, Mathf.Clamp(vectorAction[i], -1f, 1f) >= 0f); } //} if (Vector3.Distance(rocketObject.transform.position, goal.transform.position) > 50f) { //Done(); SetReward(-1f); } else { float curDistance = Vector3.Distance(goal.transform.position, rocketObject.transform.position); /*if (curDistance < lastDistance) * { * SetReward(0.1f); * } * else * { * SetReward(-0.1f); * }*/ //Debug.Log(lastDistance - curDistance); SetReward(lastDistance - curDistance); //Debug.Log("Distance: " + curDistance.ToString()); lastDistance = curDistance; } if (timeRun <= 0f && randomiseStart) { Done(); } }
// Update is called once per frame void Update() { // Blablabla /* * // Da wird geschaut ob die Maus Taste gedrückt wird * if (Input.GetMouseButtonDown(0)) * { * RaycastHit hit; * // Hier wird eine Linie von der Kamera durch den Maus Zeiger auf die Szene gezogen, wenn was getroffen wird geht er in die if rein * if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) * { * // Hier holt man sich das Objekt das getroffen wurde und kann schauen, was für eins man getroffen, also quasi geklickt hat * GameObject getroffenesObjekt = hit.transform.gameObject; * * // Zum Beispiel ist es ein Objekt mit dem Namen "Box Nummer 1" * if (getroffenesObjekt.name == "Box Nummer 1") * { * // Mach blablabla * } * } * } */ if (refreshGoal) { refreshGoal = false; SetGoal(currentGoal); } if (landingAgent.enabled) { if (rocketRB.velocity.magnitude < 0.1f) { standStillFor += Time.deltaTime; } else { standStillFor = 0f; } if (standStillFor >= 0.4f) { landingAgent.enabled = false; allOff = true; rocketController.SetThrust(0, false); rocketController.SetThrust(1, false); rocketController.SetThrust(2, false); rocketController.SetThrust(3, false); } } if (allOff) { rocketController.SetThrust(0, false); rocketController.SetThrust(1, false); rocketController.SetThrust(2, false); rocketController.SetThrust(3, false); // TODO alter int randGoal = Random.Range(0, kiNavPlanner.Stations.Count); SetGoal(kiNavPlanner.Stations[randGoal]); } if (waitForLowVelocity) { if (rocketRB.velocity.magnitude < landingVelThresh) { waitForLowVelocity = false; updateTempGoal(); } } }
public override void AgentAction(float[] vectorAction, string textAction) { //if (brain.brainParameters.vectorActionSpaceType == SpaceType.discrete) //{ for (int i = 0; i < vectorAction.Length; i++) { rocketController.SetThrust(i, Mathf.Clamp(vectorAction[i], -1f, 1f) >= 0f); } //} if (Vector3.Distance(rocketObject.transform.position, landingPlatform.transform.position + new Vector3(0f, 1.4f, 0f)) > 30f) { if (randomiseStart) { Done(); } SetReward(-3f); } else if (landingPlatformS.StandsOn(rocketObject.transform) == false) { float curDistance = Vector3.Distance(landingPlatform.transform.position + new Vector3(0f, 1.4f, 0f), rocketObject.transform.position); float velMag = rb.velocity.magnitude; if (velMag < 0.05f) { velMag = 0.05f; } float angleCos = Mathf.Cos(rocketObject.transform.rotation.eulerAngles.z * Mathf.PI / 180f); float delta = lastDistance - curDistance; float rew = delta * angleCos; if (angleCos < 0f && delta > 0f) { delta *= -1f; } SetReward(delta /* * (curDistance / velMag)*/); //Debug.Log("Distance: " + curDistance.ToString()); lastDistance = curDistance; } else if (landingPlatformS.StandsOn(rocketObject.transform)) { float velMag = rb.velocity.magnitude; float angleCos = Mathf.Cos(rocketObject.transform.rotation.eulerAngles.z * Mathf.PI / 180f); if (firstTimeEnter) { firstTimeEnter = false; enterVelocity = velMag; } velMag = 1f - velMag; if (velMag < -1f) { velMag = -1f; } //angleCos = (angleCos - 0.5f); //Done(); //Debug.Log("Reward: " + (angleCos + velMag).ToString()); SetReward(velMag * angleCos); if (randomiseStart) { Done(); } } if (timeRun <= 0f && randomiseStart) { float curDistance = Vector3.Distance(landingPlatform.transform.position + new Vector3(0f, 1.4f, 0f), rocketObject.transform.position); Done(); if (curDistance < 1.6f) { //SetReward(0.2f); } } }