When unmanned aerial vehicles (UAVs) track a moving target in complex environment, most path planning methods are difficult to combine real-time calculation and optimality. A real-time path planning method based on boundary value problem (BVP) is studied. First, a grid model of terrain is established based on UAV constraints. Then the structure of receding horizon planning ensures the real-time tracking to moving target, and the path is determined based on BVP in each horizon window. The sub-goal of horizon window is designed by line-of-sight, and the method of updating potential field dynamically and the calculation of flight direction are proposed. By comparison with other methods, the simulation results show that the method can ensure the path smooth and feasible. It can track the moving target in realtime and have some optimality, which is suitable for the mission of UAV to track moving target in complex environment.