//SF check goes in Update void Update() { if (!alive) { return; } if (!hasStopped && GetComponent <Rigidbody>().velocity.magnitude < 1f) { hasStopped = true; } if (TrackController.Instance.hasTraffic) { if (Time.time - timer < 10f) { return; } if (Time.time - checkTimer < 2f) { return; } checkTimer = Time.time; var outside = TrackController.Instance.CheckForOutsideLaneSF(); if (outside == TrackController.OutsideLane.UNSURE) { return; } if (outside == TrackController.OutsideLane.OUTSIDE) { if (!isOffroad) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "LANE"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); timer = Time.time; isOffroad = true; } } else { isOffroad = false; } } else { ProcessWheels(); } }
void OnCollisionEnter(Collision other) { if (!alive) { return; } if (Time.time - timer < 10f) { return; } if (other.gameObject.CompareTag("Obstacle")) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "OBS"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); timer = Time.time; } else if (other.gameObject.CompareTag("TrafficCar")) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "TRAF"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); timer = Time.time; } else { for (int i = 0; i < other.contacts.Length; i++) { if (other.contacts[i].thisCollider.GetType() != typeof(WheelCollider) && other.contacts[i].otherCollider.GetType() != typeof(WheelCollider)) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "ENV"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); timer = Time.time; break; } } } }
private bool ProcessWheel(Collider other) { Transform roadMesh = null; if (other.transform.parent != null && other.transform.parent.CompareTag("Road")) { roadMesh = other.transform; } if (roadMesh != null) { checkTimer = Time.time; if (TrackController.Instance.CheckForOutsideLane(roadMesh)) { if (!isOffroad) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "LANE"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); timer = Time.time; isOffroad = true; return(true); } } else { isOffroad = false; } } else if (other.GetType() == typeof(TerrainCollider)) { if (!isOffroad) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "LANE"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); timer = Time.time; isOffroad = true; } return(true); } return(false); }
void OnTriggerExit(Collider other) { if (!hasStopped && other.CompareTag("StopTrigger")) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "STOP"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); isOffroad = true; } }
void OnTriggerExit(Collider other) { if (!other.CompareTag("Player")) { return; } if (redLight && Vector3.Distance(entryPoint, other.transform.position) > checkRadius) { var infraction = new DrivingInfraction(); infraction.id = TrackController.Instance.GetInfractions().Count; infraction.speed = TrackController.Instance.car.GetComponent <Rigidbody>().velocity.magnitude; infraction.type = "LIGHT"; infraction.systemTime = System.DateTime.Now; infraction.sessionTime = Time.time - startTime; TrackController.Instance.AddInfraction(infraction); } redLight = false; }
public void Enable(int selected) { infractions = InfractionController.Instance.GetInfractions(); selectedId = selected; infractionDetails = infractions.Where(i => i.id == selected).FirstOrDefault(); }