void ChangeState() { switch (currentState) { case State.WAITING: if (dontLeaveTheRoom) { targetPosition = PathManager.manager.GetMyRoom(transform.position).RandomPoint(); currentState = State.WALKING; nextStateChange = float.PositiveInfinity; break; } if (Random.Range(0f, 1f) < danceAfinity) { // go dancing var poi = PointOfInterest.GetPoIWithTag("dancefloor")[0]; FindPathTo(poi.transform.position, poi.myRoom); currentState = State.WALKING_TO_DANCEFLOOR; nextStateChange = float.PositiveInfinity; } else { // pick point of interest and go there var pois = PointOfInterest.poi.Where(x => !x.tags.Contains("dancefloor")).ToList(); //pois = pois.OrderBy(x => x.transform.position - transform.position).ToList(); BROKE UNITY; THEREFORE TEMP REPLACED BY NEXT LINE (cannot compare Vector3) pois = pois.OrderBy(x => (x.transform.position - transform.position).magnitude).ToList(); var poi = pois[Random.Range(0, Mathf.Min(pois.Count, 3))]; FindPathTo(poi.transform.position, poi.myRoom); currentState = State.WALKING; nextStateChange = float.PositiveInfinity; } break; case State.TALKING: // Debug.Log("check for personal space distance"); if (Mathf.Abs((transform.position - talkPartner.position).magnitude - personalSpaceRadius) > 0.1f) { targetPosition = (transform.position - talkPartner.position).normalized * (personalSpaceRadius + 1f) + talkPartner.position; currentState = State.TALKING_AND_WALKING; nextStateChange = myTime + 3f; } else { nextStateChange = myTime + Random.Range(maxAvoidTime / 2, maxAvoidTime); } break; case State.TALKING_AND_WALKING: targetPosition = transform.position; currentState = State.TALKING; nextStateChange = myTime + Random.Range(maxAvoidTime / 2, maxAvoidTime); break; case State.WALKING: // change will come from personMotor or collision break; case State.WALKING_TO_DANCEFLOOR: StartDancing(); break; case State.DANCING: currentState = State.WAITING; nextStateChange = 0f; ChangeState(); break; } }