Unmanned aerial vehicles (UAVs) are used widely for data collection in wireless sensor networks (WSNs). UAVs visit the sensors to collect the data. UAV-aided data collection is a challenging problem because different paths of a UAV, i.e., visiting orders of sensors, affect energy consumption and data delivery times. The problem becomes more difficult when there are obstacles in the path of the UAV. Thus, the UAV needs to take a detour to avoid them, resulting in different travel distances and times. Therefore, this study formulated the obstacle-aware path planning problem of UAVs, i.e., the obstacle-constrained distance minimization (OCDM) problem, as an integer linear programming problem (ILP) to minimize the total traveling distances of all UAVs while considering the UAVs’ flight time constraints. First, a possible detour-points-selection algorithm called vector rotation-angle-based obstacle avoidance (VRAOA) is proposed to find the detour points around each obstacle in the environment. Then, a genetic algorithm with VRAOA (GA w/VRAOA)is developed to find the trajectories of the UAVs, using the VRAOA and Dijkstra algorithm to find a detour path if there is an obstacle between any two sensors. Finally, simulations were performed for algorithm variants, where GA w/VRAOA outperformed others.