In this paper, the real-time path avoidance problem of multirotor UAV in the case of sudden obstacles in two-dimensional environment is studied. The principle, model, and application of ant colony algorithm are analyzed. On this basis, the adaptive dynamic window ant colony algorithm is proposed, and the adaptive dynamic window method is designed; the heuristic function of adding obstacle detection factors and the double pheromone update strategy are made to the ant colony algorithm, and the improved ant colony algorithm is used to replan the path within the dynamic window that can be automatically adjusted to achieve the purpose of obstacle avoidance. A real-time simulation experiment of path planning was conducted by constructing an environment map in MATLAB. The simulation results show that with the continuous increase of the number of sudden obstacles, the real-time replacement path of multirotor UAV also gradually increases, and when approaching the obstacles, the replacement path is more dense, indicating that the adaptive window ant colony algorithm can be applied to dynamic path replacement, and the multirotor UAV can realize dynamic obstacle avoidance path optimization under the condition of sudden obstacles in a short time.