void Start() { id = simulationElement.ID; trafficManager = simulationElement.GetComponentInParent <TrafficManager>(); offset = trafficManager.transform.position; trafficManager.GetPosition(id, (trafficManager.timeController.time + lookAheadTime) % trafficManager.AnimationLength, ref lookAtPosition); lookAtPosition += offset; rotation = transform.rotation; }
void Update() { if (trafficManager.GetPosition(id, (trafficManager.timeController.time + lookAheadTime) % trafficManager.AnimationLength, ref newPos)) { //lookAtPosition = newPos + offset; lookAtPosition = Vector3.Lerp(lookAtPosition, newPos + offset, 0.04f); Vector3 dir = lookAtPosition - transform.position; if (dir.sqrMagnitude > 0.01f) { rotation = Quaternion.Lerp(rotation, Quaternion.LookRotation(dir, Vector3.up), 0.04f); transform.rotation = rotation; } else { transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.identity, 0.02f); } } else { transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.identity, 0.02f); } }