The formation of autonomous underwater vehicle (AUV) in the three-dimensional environment is very important for carrying out complex ocean tasks. During formation sailing, it is necessary to consider avoiding obstacles while maintaining the formation. In this paper, an AUV formation obstacle avoidance method based on virtual structure and artificial potential field method is proposed. Firstly, a complete mathematical modeling of AUV is carried out, and a sliding mode position tracker based on virtual position points is designed based on this model. Then the tracking points of each AUV in the formation are calculated according to the expected trajectory and formation feature structure to ensure that the spacing between AUVs meets the requirements of the formation. Finally, the artificial potential field method is introduced into the position tracker to avoid obstacles between the obstacle and the AUV. Five groups of simulation experiments of parallel formation, vertical formation, cross formation, triangular formation and unknown complex environment are designed. The formation scalability of the algorithm is simulated and compared with the virtual leader method in related references. Finally, KKSwarm platform is used to conduct a real simulation in 2D environment to verify the effectiveness of the proposed algorithm.The experimental results show that the proposed method can effectively realize the formation navigation of multiple underwater vehicles and successfully avoid obstacles, which provides an effective method to solve the problem of the formation obstacle avoidance of underactuated AUV.