IEnumerator WaitAndGo(StopCounts stopCount) { // stop bus navAgent.Stop(); print(this.name + " loading " + stopCount.waiting.ToString() + " passengers at " + stopOrder[nextStopIdx - 1]); this.loading = stopCount.waiting; // start loading while (stopCount.waiting > 0) { stopCount.waiting--; // load passenger this.loading--; passengersBoarded++; yield return(new WaitForSeconds(1f)); //Wait // print(this.name + " passengers waiting: " + stopCount.waiting); AddReward(rwdPsxPickup); } // confirm all passengers picked up (by this or other bus) this.loading = 0; // start bus navAgent.Resume(); }
void OnTriggerEnter(Collider collision) { // print (this.name + " collided with " + collision.gameObject.tag); // if at the next stop if (collision.gameObject.tag == currentStop) { // Reward reaching next stop // AddReward(rwdEachStop); // Reward maintaining distance float dist = Vector3.Distance(otherBus.transform.position, this.transform.position); // print(busIdx.ToString() + " distance to other: " + dist); if (dist > 700) { AddReward(rwdDistance); } // Get stop details StopCounts stopCount = collision.gameObject.GetComponent <StopCounts>(); if (stopCount.waiting > 0) { StartCoroutine(WaitAndGo(stopCount)); } // only stop if px waiting // Update stop updateNextStop(); // if full circle completed, mark as episode done if (currentStop == "Stop 1") { AddReward(rwdCircuit); Done(); } // if returned to previous stop then penalise heavily } else if (collision.gameObject.tag == previousStop) { AddReward(rwdPrevStop); } }