void Update() { if (calculatePath) { calculatePath = false; Vector2[] path = AISystem.GetPath(GridSystem.System.PosToCoord(walkOnSide, transform.position), GridSystem.System.PosToCoord(walkOnSide, targetPosition), walkOnSide); transform.position = GridSystem.System.ToGridPosition(GridSystem.System.CoordToPos(walkOnSide, path[0])); } }
private IEnumerator testenum() { yield return(new WaitForSeconds(1)); //print("Own position: " + GridSystem.System.CanMoveTo(walkOnSide, GridSystem.System.GetGridCoords(transform.position, true))); //print("time1: " + Time.time.ToString()); //MonoBehaviour.print("start: "+GridSystem.System.PosToCoord(walkOnSide, transform.position)); //MonoBehaviour.print("end :"+ GridSystem.System.PosToCoord(walkOnSide, targetPosition)); Vector2[] path = AISystem.GetPath(GridSystem.System.PosToCoord(walkOnSide, transform.position), GridSystem.System.PosToCoord(walkOnSide, targetPosition), walkOnSide); //print("time2: " + Time.time.ToString()); //transform.position = GridSystem.System.ToGridPosition(GridSystem.System.CoordToPos(walkOnSide, path[0])); //print("Path lenght: " + path.Length); StartCoroutine(walkTo(path)); }
private IEnumerator fleeFromPACMAN() { for (int i = 0; i < 3; i++) { yield return(new WaitForFixedUpdate()); } do { //int i = 0; //yield return new WaitForSeconds(1); float counter = 3; do { yield return(new WaitForFixedUpdate()); counter -= Time.fixedDeltaTime; //print(ReachedPosition()); if (!initiated) { goto skipWaiting; } }while ( //counter > 0 && //!ReachedPosition() !ReachedTarget() && counter > (!hasBerry ? -10 : -2) ); if (ReachedTarget() && ItemManager.Manager.IsSpawnPosition(GridSystem.System.PosToCoord(walkOnSide, transform.position), walkOnSide)) { StartCoroutine(GetBerry()); } skipWaiting: initiated = true; Vector2 target = Vector2.zero; Vector2 coord = GridSystem.System.PosToCoord(walkOnSide, transform.position); if (MultigridPlayer.player.CurrentWalkOnSide != CurrentWalkOnSide) { int targetTile = GetWalkableTile((int)coord.x + (int)(coord.y * GridSystem.System.Count)); targetPosition = GridSystem.System.ToGridPosition(GridSystem.System.CoordToPos(walkOnSide, new Vector2(targetTile % GridSystem.System.Count, Mathf.Floor(targetTile / GridSystem.System.Count)))); } else { //walk to berry if (!hasBerry) { //Vector2 target = ItemManager.Manager.GetRandomBerry(walkOnSide); if (target != Vector2.zero) { targetPosition = GridSystem.System.ToGridPosition(GridSystem.System.CoordToPos(walkOnSide, target)); } } else { targetPosition = MultigridPlayer.player.transform.position; } } //print("side: " + walkOnSide + ", target:" + GridSystem.System.PosToCoord(walkOnSide, targetPosition)); pathIndex = 0; path = AISystem.GetPath(GridSystem.System.PosToCoord(walkOnSide, transform.position), GridSystem.System.PosToCoord(walkOnSide, targetPosition) //target , walkOnSide); //print("side: " + walkOnSide + ", path len: " + path.Length); //print("side: " + walkOnSide + ", pos: " + GridSystem.System.PosToCoord(walkOnSide, transform.position) + ", targ: " + GridSystem.System.PosToCoord(walkOnSide, targetPosition)); /* * Vector2[] path = AISystem.GetPath(GridSystem.System.PosToCoord(walkOnSide, transform.position), GridSystem.System.PosToCoord(walkOnSide, targetPosition), walkOnSide); * * * float counter = 0, counter2 = 0; ; * if (path.Length > 0) * { * do * { * yield return new WaitForFixedUpdate(); * transform.position = Vector3.MoveTowards(transform.position, GridSystem.System.ToGridPosition(GridSystem.System.CoordToPos(walkOnSide, path[Mathf.Clamp(i,0,path.Length-1)])), maxMovement); * //transform.position = GridSystem.System.ToGridPosition(GridSystem.System.CoordToPos(walkOnSide, path[Mathf.Clamp(i, 0, path.Length - 1)])); * //i++; * counter += Time.fixedDeltaTime; * counter2 += Time.fixedDeltaTime; * if(counter2 >= (1f / movementSpeed * Time.fixedDeltaTime)) { * counter2 = counter2 % (1f / movementSpeed * Time.fixedDeltaTime); * i++; * } * } * while (counter < 1); * * } * else * { * yield return new WaitForFixedUpdate(); * } */ }while (true); }