In this paper, aiming at the problems of large randomness, low convergence accuracy, and easy falling into local optimum in the application of sparrow search algorithm to UAV three-dimensional path planning, a dynamic step opposition-based learning sparrow search algorithm is proposed. The algorithm first uses a good point set in the population initialization phase to improve the quality of the initial solution; secondly, the piecewise dynamic step size is used to optimize the update formula of the discoverer, and the extensive search is carried out in the early stage of the iteration. In the later stage, the known area is mined as much as possible to improve the search accuracy and convergence speed of the algorithm. Then, the crazy operator is integrated to optimize the predator update formula and improve the local search ability. Finally, t-distribution opposition-based learning is used to prevent the algorithm from falling into the local optimum. In this paper, the effectiveness of the improved algorithm is verified by six test functions and applied to the three-dimensional path planning of UAVs. The experimental results show that the proposed algorithm has a faster convergence speed than the traditional algorithm, and the planned path is shorter.