A computer-implemented method for guiding a vehicle from a source (S,302) to a target (T,304) within a scenario with obstacles, the method comprising the steps of: a) - establishing (202,204) the source (S,302) as a starting point (S'); b) - computing a subpath from the starting point (S') to the target (T,304); c) detecting if an obstacle (0,510,520) crosses the computed subpath; d) - computing (208, 210) a plurality of subpaths avoiding the detected obstacle (O,510,520), each subpath connecting the starting point (S') to a waypoint of an outer boundary of the detected obstacle (O,510,520); e) - detecting if a further obstacle crosses each of the plurality of subpaths; f) -repeating the steps d) - e) for each further obstacle; g) computing a priority value for each waypoint, wherein the priority value is computed based on: the distance between the waypoint and the target (T,304) regardless of eventual obstacles located between the waypoint and the target (T,304), and the accumulated distance from the source (S,302) to the waypoint, wherein the accumulated distance comprises at least the distance between the starting point and an ending point of at least one computed obstacle-free subpath from the source (S,302) to the waypoint, the distance being defined according to a pre-established metric; h) storing (216, 218) each waypoint and its corresponding priority value in a list of potential waypoints; the method characterized by i) selecting the highest priority waypoint according to a minimum value of the metric in the list as a starting point (S'), and j) repeating steps b) to i) until the target (T,304) is reached; k) obtaining an optimal path by backtracking waypoints from the target (T,304) to the source (S,302); l) - guiding the vehicle according to the optimal path. a) - establishing (202,204) the source (S,302) as a starting point (S'); b) - computing a subpath from the starting point (S') to the target (T,304); c) detecting if an obstacle (0,510,520) crosses the computed subpath; d) - computing (208, 210) a plurality of subpaths avoiding the detected obstacle (O,510,520), each subpath connecting the starting point (S') to a waypoint of an outer boundary of the detected obstacle (O,510,520); e) - detecting if a further obstacle crosses each of the plurality of subpaths; f) -repeating the steps d) - e) for each further obstacle; g) computing a priority value for each waypoint, wherein the priority value is computed based on: the distance between the waypoint and the target (T,304) regardless of eventual obstacles located between the waypoint and the target (T,304), and the accumulated distance from the source (S,302) to the waypoint, wherein the accumulated distance comprises at least the distance between the starting point and an ending point of at least one computed obstacle-free subpath from the source (S,302) to the waypoint, the distance being defined according to a pre-established metric; the distance between the waypoint and the target (T,304) regardless of eventual obstacles located between the waypoint and the target (T,304), and the accumulated distance from the source (S,302) to the waypoint, wherein the accumulated distance comprises at least the distance between the starting point and an ending point of at least one computed obstacle-free subpath from the source (S,302) to the waypoint, the distance being defined according to a pre-established metric; h) storing (216, 218) each waypoint and its corresponding priority value in a list of potential waypoints; the method characterized by i) selecting the highest priority waypoint according to a minimum value of the metric in the list as a starting point (S'), and j) repeating steps b) to i) until the target (T,304) is reached; k) obtaining an optimal path by backtracking waypoints from the target (T,304) to the source (S,302); l) - guiding the vehicle according to the optimal path.