Purpose The purpose of this study is to propose a path-planning strategy based on the velocity-virtual spring method to realize collision-free tasks in dynamic environments and further improve the effect. Design/methodology/approach By considering factors such as the relative velocity and direction of dynamic obstacles, the repulsive force of the robot is improved, thereby enhancing the adaptability of the strategy and achieving flexible and effective avoidance against dynamic obstacles. The attraction formula has been designed to allow the robot to have better smooth changes and higher gradients near the target, helping robots better reach the target and follow formations. Moreover, to meet the demands of the various stages during the driving process, the null space behavioral control is used to solve multi-task conflict problems and strengthen formation coordination and control. Findings Comparison of the planning path and formation effects through simulation and physical experiments, the results of this study show that the algorithm proposed can successfully maintain formation stability and plan smooth and safe paths in static or dynamic environments. Originality/value This paper proposes a path-planning strategy based on the velocity-virtual spring method to plan collision-free paths for formation in dynamic environments.