Find distance between human player and monster player in a maze

Hi,

I am currently developing a unity game and I am stuck on a problem. In my game, there is a maze as well as human players and monster players. If human and monster players are approaching each other, an audio or a visual warning shall indicate this. Therefore, I need to calculate the distance between monster and human player. The problem is, that I don’t want to calculate the aerial distance between both objects, because there are tons of walls in the maze. A monster on the other side of a wall is “near” regarding only the aerial distance, but not if I calculate the distance based on the passages in the maze.

I have some approaches in mind, for instance returning the graph of the maze and use the human and monster player as nodes and calculate the distance between them based on edges.

Does anyone know a more simple solution for this or had a similar problem?

Thanks!

Calculating the distance with a pathfinding algorithm would work. Not sure how the maze is set up, but you can probably implement A* or Dijkstra’s algorithm to find the shortest path and distance.