I started a small game where the player clicks on the "map" to complete the tasks. The user can only move the player X squares for each click. How to limit the player to the inability to move around the blocks?
Right now, the player can move around the filled area, but I do not want this to be possible, the user should be able to move only where there are no filled squares. (I.e. a green track.)
I am currently calculating the length of the vector between the start and end points to see if the user can go that far, but I donβt know how to check if there is a wall in the way and then calculate the new length.,
(The red path is the shortest path, the green path is the path I'm trying to get the player to go. M is the player.)

source share