private void OnTriggerExit(Collider other) { AICarBehaviour otherCar = other.GetComponent <AICarBehaviour>(); if (otherCar != null) { carsInIntersection.Dequeue(); } }
//shoots rays to detect obstacles void raycast() { float hitDist; GameObject obstacle = GetDetectedObstacles(out hitDist); //Check if we hit something if (obstacle != null) { NavMeshAgent otherVehicle = null; otherVehicle = obstacle.GetComponent <NavMeshAgent>(); AICarBehaviour otherCar = obstacle.GetComponent <AICarBehaviour>(); if (otherVehicle != null) { //Check if it's front vehicle float dotFront = Vector3.Dot(this.transform.forward, otherVehicle.transform.forward); //If detected front vehicle speed is lower, decrease max speed if (otherVehicle.speed < agent.speed && dotFront > .8f) { agent.speed = (otherVehicle.speed - 0.25f); } //If the two vehicles are too close, and facing the same direction, brake the ego vehicle if (hitDist < emergencyBrakeDist && dotFront > .8f) { stateMachine.TransitionTo("Stop"); } if (otherCar.stateMachine.CurrentState == otherCar.stateMachine.GetState("Go")) { // Debug.Log("They are going"); if (this.stateMachine.CurrentState != this.stateMachine.GetState("Go")) { Invoke("CanRaycast", 1f); } } else { this.stateMachine.TransitionTo("Stop"); } if (hitDist < slowDownDist) { agent.speed = maxSpeed * 0.5f; } } } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "damageable")//will change later { AICarBehaviour car = other.gameObject.GetComponent <AICarBehaviour>(); if (car != null) { ; carsWaiting.Enqueue(car); car.stateMachine.TransitionTo("Stop"); car.currentPath = paths[Random.Range(0, paths.Length)];//choose a new path for the car // car.UpdateCurrentPath(); } } }