Unmanned aerial vehicles have a wide range of applications. An intelligent optimization algorithm based on the traditional bat algorithm (BA) is investigated in this paper for UAV flight path planning in a static complex environment. The primary goal of this work is to develop a safer flight path while considering the feasibility of the UAV and the requirements for safe operation. This research proposes an improved spherical coordinate and truncated average stable strategy-based bat optimization algorithm (TMS-SBA). The algorithm uses the UAV’s motion space to encode the operator, and by substituting a new bat for the worst of the old one after each iteration to increase population diversity, the algorithm can converge quickly in a complex environment while maintaining stable operation. In addition, the flight path is smoothly generated by using B-spline curves to make the planned path suitable for UAV. MATLAB simulation experiments show that, compared with other traditional swarm intelligent algorithms, TMS-SBA can successfully generate feasible and effective optimal solutions in complex environments and plan shorter, safer, and more accessible flight paths for UAV.