We address the problem of how UAVs in the three-dimensional environment can reasonably plan a path that avoids obstacles from the starting point to a target point. UAV path planning and obstacle avoidance method are proposed, based on the combination of improved particle swarm optimization and rolling strategy methods. First, the proposed method uses the UAV as the center and uses sensors to establish a UAV visual area model.Next, scrolling strategies are combined to obtain information about the environment surrounding the UAV.Lastly, the improved particle swarm algorithm is used to search the path, with the addition of integrated corner control to improve path smoothness. Pheromone and heuristic functions are added to the traditional particle swarm optimization algorithm to enhance the algorithm's global search capability, and the parameters are specifically designed to improve the algorithm's convergence speed. Simulation results show that the proposed method can achieve real-time obstacle avoidance, the planned path is relatively smooth, and the improved algorithm has higher convergence than the traditional algorithm.