public void Update() { if (dataflow != null) { dataflow.Run(); } if (moving) { if (planet.walkable[(int)(transform.position.x + transform.up.x), (int)(transform.position.y + transform.up.y)]) { transform.position = Vector3.MoveTowards(transform.position, destination, moveSpeed * Time.deltaTime); } if (transform.position == destination) { moving = false; movingStarted = false; } } if (path != null && path.Count > 0) { if (!positionChangeStarted) { if (planet.walkable[(int)path[path.Count - 1].x, (int)path[path.Count - 1].y]) //TODO: Untested: send drone invalid path through obstacles { positionChangeStarted = true; planet.walkable[(int)transform.position.x, (int)transform.position.y] = true; planet.walkable[(int)path[path.Count - 1].x, (int)path[path.Count - 1].y] = false; obstacleAhead = false; } else { obstacleAhead = true; } } if (positionChangeStarted) { Vector3 newPosition = Vector3.MoveTowards(transform.position, new Vector3(path[path.Count - 1].x, path[path.Count - 1].y, transform.position.z), moveSpeed * Time.deltaTime); transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(Vector3.forward, newPosition - transform.position), rotateSpeed * Time.deltaTime); transform.position = newPosition; if (transform.position.x == path[path.Count - 1].x && transform.position.y == path[path.Count - 1].y) { positionChangeStarted = false; path.RemoveAt(path.Count - 1); } } } }