void UpdatePosition() { CheckForPlayerOnTheWay(); CheckForCastleOnTheWay(); int xCoordinate = (int)Math.Round(transform.position.x); int zCoordinate = (int)Math.Round(transform.position.z); if (TankUtils.IsCenterOfField(gameObject, xCoordinate, zCoordinate)) { currentIndex++; if (currentIndex == path.Count) { bool stayInPlace = ArrivedToDestination(); if (stayInPlace) { return; } } Vector3 nextRotation = TankUtils.FindNextRotation(gameObject, path[currentIndex]); nextRotation.y -= transform.rotation.eulerAngles.y; transform.Rotate(nextRotation); } TankUtils.GoToNewPosition(gameObject); Invoke("UpdatePosition", Constants.UpdateMethodDelay); }
void RotateToFreeNeighbour(int xCoordinate, int zCoordinate) { stepCounter = 5; List <Vector2> freeFields = FindFreeNeighbourFields((xCoordinate - 1) / 2, (zCoordinate - 1) / 2); if (freeFields.Count > 0) { int randomIndex = GetRandom(freeFields.Count - 1); Vector3 nextRotation = TankUtils.FindNextRotation(gameObject, freeFields[randomIndex]); nextRotation.y -= transform.rotation.eulerAngles.y; transform.Rotate(nextRotation); } else { Debug.Log("Nema slobodnog komsije!"); transform.Rotate(new Vector3(0, Constants.AngleLeft, 0)); return; } }
void RotateToCastle() { Vector2 castleField; int currentRow = ((int)transform.position.x - 1) / 2; int currentColumn = ((int)transform.position.z - 1) / 2; if (currentRow == Constants.CastleMinRow) { castleField = new Vector2(currentRow + 1, currentColumn); } else if (currentColumn == Constants.CastleMinColumn) { castleField = new Vector2(currentRow, currentColumn + 1); } else { castleField = new Vector2(currentRow, currentColumn - 1); } Vector3 nextRotation = TankUtils.FindNextRotation(gameObject, castleField); nextRotation.y -= transform.rotation.eulerAngles.y; transform.Rotate(nextRotation); }