Obstacle avoidance is a significant research content in multi-agents formation control. The obstacle avoidance of multi-agents systems is investigated in this paper, and an improved artificial potential field method (IAPF) is proposed to avoid unknown obstacles in multi-agent formation. Aiming at improving the efficiency of formation avoidance and solving the non-reachable and local minima problems, the dynamic sub-target algorithm is proposed. The proposed method enables the multi-agent system (MASs) to avoid obstacles smoothly and quickly and complete formation tasks in complex environments by tracking dynamic sub-target as well, in which the position and motion direction of adjacent agents are taken into account in the selection of a sub-target for the formation efficiency. In addition, a variable potential field range is defined to ensure the safety of the formation. Finally, several simulation results verify the superiority and effectiveness of the proposed approach.