void Start() { pathControler = gameObject.GetComponent <PathControler>(); cityControler = gameObject.GetComponent <CityControler>(); acoControler = gameObject.GetComponent <AcoControler>(); animationControler = gameObject.GetComponent <AnimationControler>(); dataInit(); ui = player.GetComponent <PlayerUiControler>(); }
// Use this for initialization void Start() { timeLeft = lengthOfAnimation; cityControler = gameObject.GetComponent <CityControler>(); acoControler = gameObject.GetComponent <AcoControler>(); pathControler = gameObject.GetComponent <PathControler>(); pheromons = null; antPefab = Resources.Load <GameObject>("CityTestScene/Prefab/Ant"); distanceControler = gameObject.GetComponent <DistanceControler>(); }
private void animateAnt(ref AntData ant, List <int> path) { if (ant.timeLeftOnPath > 0) { ant.timeLeftOnPath -= Time.deltaTime; GameObject cityFrom = cityControler.citys[cityControler.activeCitysIndex[path[ant.currentDest - 1]]]; GameObject cityTo = cityControler.citys[cityControler.activeCitysIndex[path[ant.currentDest]]]; Transform child1 = PathControler.findDeepChild(cityFrom.transform, "Outter"); Transform child2 = PathControler.findDeepChild(cityTo.transform, "Outter"); if (!child1 || !child2) { return; } float xRadius = (child2.position - child1.position).magnitude / 2; float yRadius = xRadius / 2; float minAngle = -90; float maxAngle = 90; float angle = Mathf.LerpAngle(minAngle, maxAngle, (ant.timePerPath - ant.timeLeftOnPath) / ant.timePerPath); var test = ant.antGameObject.transform.InverseTransformPoint(child2.position); float x = Mathf.Sin(Mathf.Deg2Rad * angle) * test.magnitude; float z = Mathf.Cos(Mathf.Deg2Rad * angle) * test.magnitude / 2; GameObject child = ant.antGameObject.transform.GetChild(0).gameObject; var move = new Vector3(x, z, 0); child.transform.localPosition = move; //update pos /* GameObject cityFrom = cityControler.citys[cityControler.activeCitysIndex[path[ant.currentDest-1]]]; * GameObject cityTo= cityControler.citys[cityControler.activeCitysIndex[path[ant.currentDest]]]; * if(!cityFrom || !cityTo) * { * return ; * }*/ } else { if (ant.currentDest < path.Count - 1) { ++ant.currentDest; int i, j; i = cityControler.activeCitysIndex[path[ant.currentDest - 1]]; j = cityControler.activeCitysIndex[path[ant.currentDest]]; ant.timePerPath = distanceControler.distanceMatrix[i, j] / acoControler.antSpeed; ant.timeLeftOnPath = distanceControler.distanceMatrix[i, j] / acoControler.antSpeed; GameObject cityFrom = cityControler.citys[cityControler.activeCitysIndex[path[ant.currentDest - 1]]]; GameObject cityTo = cityControler.citys[cityControler.activeCitysIndex[path[ant.currentDest]]]; Transform child1 = PathControler.findDeepChild(cityFrom.transform, "Outter"); Transform child2 = PathControler.findDeepChild(cityTo.transform, "Outter"); if (!child1 || !child2) { return; } Vector3 pos = child1.position + (child2.position - child1.position) / 2; ant.antGameObject.transform.position = pos; var rot = Quaternion.FromToRotation(Vector3.right, child2.position - child1.position); ant.antGameObject.transform.rotation = rot; //ant.antGameObject.transform.position = cityFrom.transform.position; } else if (!ant.finished) { ++numAntsFinished; ant.finished = true; } } }