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 UpdatePosition() { CheckEdgePositions(); CheckForPlayerOnTheWay(); CheckForCastleOnTheWay(); int xCoordinate = (int)Math.Round(transform.position.x); int zCoordinate = (int)Math.Round(transform.position.z); if (TankUtils.IsCenterOfField(gameObject, xCoordinate, zCoordinate)) { stepCounter--; Vector2 nextField = FindNextField(); if (nextField.Equals(Vector2.negativeInfinity) || mapManagerScript.obstacleMatrix[(int)nextField.x, (int)nextField.y]) { RotateToFreeNeighbour(xCoordinate, zCoordinate); if (stepCounter == 0) { stepCounter = 5; } } else if (stepCounter == 0) { stepCounter = 5; RotateToFreeNeighbour(xCoordinate, zCoordinate); } } TankUtils.GoToNewPosition(gameObject); }