void Awake() { if (instance == null) { instance = this; } }
protected Vector3 NextPosition(IntersectionController intersection) { if (GameController.mode.Equals(GameController.GameMode.Frightened)) { System.Random random = new System.Random(); int randomIntersectionIndex; GameObject randomIntersection = intersection.gameObject; do { randomIntersectionIndex = random.Next(0, intersection.IntersectionList ().Length); randomIntersection = intersection.IntersectionList ()[randomIntersectionIndex]; } while (randomIntersection == null); return randomIntersection.transform.position; } float minDistance = float.MaxValue; GameObject nextGameObject = intersection.gameObject; GameObject[] intersections = intersection.IntersectionList (); System.Array.Reverse (intersections); for (int intersectionIndex = 0; intersectionIndex < intersections.Length; intersectionIndex++) { GameObject childIntersection = intersections [intersectionIndex]; if (childIntersection != null && childIntersection != previousIntersection) { float childIntersectionDistance = Vector3.Distance (intersection.transform.position + offsetVectors [intersectionIndex] * intersectionOffset, target); if (childIntersectionDistance < minDistance) { minDistance = childIntersectionDistance; nextGameObject = childIntersection; } } } return nextGameObject.transform.position; }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Intersection")) { m_intController = other.GetComponent <IntersectionController>(); m_phase = m_intController.GetPhase(transform.forward); m_inIntersection = true; } }
void OnTriggerEnter(Collider collider) { if (collider.transform.parent != null && collider.transform.parent.name == "Intersections") { IntersectionController intersection = collider.GetComponent <IntersectionController> (); nextPosition = NextPosition(intersection); previousIntersection = collider.gameObject; } }
bool GetFirstIntersection() { if (Physics.Raycast(rayToCast, out rayHit, 200f)) { target = rayHit.point; return((intersection = rayHit.collider.GetComponent <IntersectionController>()) != null); } return(false); }
public Vector3 NextWaypoint(ref CarHeading heading, out IntersectionController intersection, AI_CarController car) { carsCount--; RemoveLightListener(heading, car); Vector3 waypoint = new Vector3(); Direction dir = Direction.Undefined; int compare = 10; foreach (var neighbor in neighbors) { if (neighbor.Value.carsCount < compare) { if (NoGoDirection(heading) == neighbor.Key) { continue; } else { compare = neighbor.Value.carsCount; dir = neighbor.Key; } } } intersection = neighbors[dir]; intersection.AddCarToIntersection(); switch (dir) { case Direction.North: waypoint = intersection.North.position; heading = CarHeading.North; break; case Direction.South: waypoint = intersection.South.position; heading = CarHeading.South; break; case Direction.East: waypoint = intersection.East.position; heading = CarHeading.East; break; case Direction.West: waypoint = intersection.West.position; heading = CarHeading.West; break; } intersection.AddCarToStreetLightEvent(heading, car); return(waypoint); }
public void Move(IntersectionController.Direction direction) { switch (direction) { case IntersectionController.Direction.left: Left(); break; case IntersectionController.Direction.right: Right(); break; case IntersectionController.Direction.straight: Straight(); break; } }
private void Update() { if (m_following) { m_currentSpeed = m_carController.GetCurrentSpeed(); } else if (m_inIntersection && !runRed) { if (!m_slowingDown) { float stop_dist = Mathf.Abs(transform.position.z - m_intController.stop_z); float actual_stop_dist = (m_currentSpeed * m_currentSpeed) / (2f * deceleration); if (stop_dist <= actual_stop_dist) { m_slowingDown = true; } } else { m_currentSpeed -= deceleration * Time.deltaTime; if (m_currentSpeed < 0f) { m_currentSpeed = 0f; } } if (m_phase.CurrentState == PhaseState.ACTIVE) { m_slowingDown = false; m_inIntersection = false; m_phase = null; m_intController = null; } } else { m_currentSpeed += acceleration * Time.deltaTime; if (m_currentSpeed > max_speed) { m_currentSpeed = max_speed; } } if (m_inIntersection) { m_intController.CheckCar(this); } }
void GetNeighbors() { Ray[] rays = new Ray[4] { new Ray(transform.position, Vector3.forward), new Ray(transform.position, Vector3.right), new Ray(transform.position, Vector3.back), new Ray(transform.position, Vector3.left) }; RaycastHit hit; for (int i = 0; i < rays.Length; i++) { if (Physics.Raycast(rays[i], out hit, 200f)) { if (hit.collider.tag == "Intersection") { IntersectionController neighbor = hit.collider.GetComponent <IntersectionController>(); switch (i) { case 0: neighbors.Add(Direction.North, neighbor); break; case 1: neighbors.Add(Direction.East, neighbor); break; case 2: neighbors.Add(Direction.South, neighbor); break; case 3: neighbors.Add(Direction.West, neighbor); break; } } } } }
protected Vector3 NextPosition(IntersectionController intersection) { if (GameController.mode.Equals(GameController.GameMode.Frightened)) { System.Random random = new System.Random(); int randomIntersectionIndex; GameObject randomIntersection = intersection.gameObject; do { randomIntersectionIndex = random.Next(0, intersection.IntersectionList().Length); randomIntersection = intersection.IntersectionList()[randomIntersectionIndex]; } while (randomIntersection == null); return(randomIntersection.transform.position); } float minDistance = float.MaxValue; GameObject nextGameObject = intersection.gameObject; GameObject[] intersections = intersection.IntersectionList(); System.Array.Reverse(intersections); for (int intersectionIndex = 0; intersectionIndex < intersections.Length; intersectionIndex++) { GameObject childIntersection = intersections [intersectionIndex]; if (childIntersection != null && childIntersection != previousIntersection) { float childIntersectionDistance = Vector3.Distance(intersection.transform.position + offsetVectors [intersectionIndex] * intersectionOffset, target); if (childIntersectionDistance < minDistance) { minDistance = childIntersectionDistance; nextGameObject = childIntersection; } } } return(nextGameObject.transform.position); }
public void SetIntersectionController(IntersectionController cont) { intersectionController = cont; }
void OnLevelWasLoaded(int level) { switch (level) { case 0: //Start Debug.Log("Scene Loaded: StartScene"); break; case 1: //Lobby Debug.Log("Scene Loaded: Lobby"); if (motionBase != null) { motionBase.transform.position = new Vector3(0.0f, 1.3f, 0.0f); } lobbyInstructions = GameObject.FindGameObjectWithTag("LobbyInstructions"); lobbyInstructions.SetActive(false); breakInstructions = GameObject.FindGameObjectWithTag("BreakInstructions"); breakInstructions.SetActive(false); finishedInstructions = GameObject.FindGameObjectWithTag("FinishedInstructions"); finishedInstructions.SetActive(false); SelectionSlider slider = lobbyInstructions.GetComponentInChildren <SelectionSlider>(); slider.OnBarFilled += slider_OnBarFilled; SelectionSlider slider2 = breakInstructions.GetComponentInChildren <SelectionSlider>(); slider2.OnBarFilled += slider_OnBarFilled; targetOne = GameObject.FindGameObjectWithTag("TargetOne"); targetTwo = GameObject.FindGameObjectWithTag("TargetTwo"); if (targetOne != null && targetTwo != null) { targetOneImage = targetOne.GetComponentInChildren <Image>(); targetTwoImage = targetTwo.GetComponentInChildren <Image>(); targetOneImage.CrossFadeAlpha(0.0f, 0.1f, true); targetTwoImage.CrossFadeAlpha(0.0f, 0.1f, true); targetOne.SetActive(false); targetTwo.SetActive(false); targetOneFadedOut = true; targetTwoFadedOut = true; } if (runNumber > 0 && runNumber % numberOfRunsBeforeBreak == 0) { breakInstructions.SetActive(true); onBreak = true; } cameraFade.FadeIn(false); break; case 2: //City Debug.Log("Scene Loaded: City"); condition = conditions.Dequeue(); if (recorder != null && !recorder.currentelyRecording()) { recorder.startRecording("PedSimCity_" + participantID + "_Run" + runNumber + "_Condition" + condition); } trafficLightChangeDelay = originalTrafficChangeDelay; if (motionBase != null) { motionBase.transform.position = motionBaseStartPosition; if (runNumber > 0) { motionBase.transform.Rotate(Vector3.up, 180f); } } if (guiArrows != null) { guiArrows.Hide(); } controller = GameObject.FindGameObjectWithTag("TrialIntersection").GetComponent <IntersectionController>(); targetVehicle = GameObject.FindGameObjectWithTag("TrialVehicle"); //period that the pedestrain light counts down to RED/DON'T WALK in s //float pedestrianChangeInterval = streetWidth / walkingSpeed; //time from start of vehicle movement to ped light green, in s float goSignalDelay = fadeInDelay + trafficLightChangeDelay + trafficLightYellowInterval + vehicleClearanceInterval + walkInterval; Debug.Log("Go signal delay: " + goSignalDelay); timer = goSignalDelay; //if condition == 0, we are in the no car condition, disable target car if (condition == 0) { targetVehicle.SetActive(false); Debug.Log("Condition 0: trial car disabled."); } else { float trialCarOffset = calculateTrialCarOffset(goSignalDelay); Debug.Log("Condition " + condition + ":"); Debug.Log("trial car offset: " + trialCarOffset); //if we're an even condition we need to flip the car around for the near lane trials if (condition % 2 == 0) { targetVehicle.transform.Rotate(Vector3.up, 180); targetVehicle.transform.position = new Vector3(targetVehicle.transform.position.x, 0, -49.8f); } Vector3 trialCarPosition = new Vector3(targetVehicle.transform.position.x + trialCarOffset, 0, targetVehicle.transform.position.z); targetVehicle.transform.position = trialCarPosition; Debug.Log("new trial car position: " + trialCarPosition.ToString()); } cameraFade.FadeIn(false); break; default: Debug.Log("Scene Loaded: " + level); break; } }