Y
Y
Yura Mailler2021-08-10 21:23:40
Unity
Yura Mailler, 2021-08-10 21:23:40

How to determine where the wall is?

Hello! I am making a game where the character walks through the maze (on the grid), the maze has walls and I am puzzled not knowing how to find out if there is a wall ahead of the player, whether he can go there or not. There was an idea to hang a script on all walls that finds the distance from the wall and the player, and if the player is near the wall, then forbid him to move in that direction, but I didn’t figure out how to interact with the walls, I wanted to hang colliders on them and in the code when interacting with check the distance with a collider, and then forbid moving towards the wall at a certain distance, but that's just how to understand on which axis the wall is located so that in the code to prohibit movement in that direction.
Perhaps there is another way to solve my problem, and in general my idea is very dreary, because it will be necessary to weigh the colliders again when creating a new level, but I just thought of it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2021-08-10
@Griboks

So you put up these walls yourself. So you already know where they are.
But you can also hang a collider-trigger on the player.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question