Skip to main content
1 of 5

How to find the nearest object from another, in a non tile based game where obstacles are present?

Like in this example below , consider that object A has to determine which object is closer ,object B or object C . The pink rectangle is an obstacle . Now if we consider the euclidean distance, object B will be closer but due to the presence of an obstacle euclidean distance will give false answers .

Another solution would be to find the distance using pathfinding algorithm , which will give the correct solution , but will be slow . A simple case

What will be the ideal solution of this problem , in a game where thousands of possible target entities may be present .