Geographic routing scales well in sensor networks, mainly due to its stateless nature. Most of the algorithms in this area are concerned with guaranteeing a path toward the destination in the context of any network topology, while the optimality of the path is of little interest. In this paper, we are presenting a novel geographic routing algorithm with obstacle avoidance properties. It aims at finding the optimal path from a source to a destination when some areas of the network are unavailable for routing due to low local density or obstacle presence. It locally and gradually with time (but, as we show, quite fast) evaluates and updates the quality of the previously used paths and ignores non-optimal paths for further routing. By means of extensive simulations, we are comparing its performance to existing state of the art protocols, showing that it performs much better in terms of path length and hop count thus minimizing latency, overall traffic and energy consumption. Copyright © 2008 John Wiley & Sons, Ltd.