Following and going around the edges of the boxes

Hi everyone, Firstly, sorry for my English. I want to do my character follow around the edges of the boxes. Nearly one week, I’m working with the checking collider but it did not work stable. But Now I stopped work in this way. So my question is this. What is the best idea to follow corners?

First, are your levels all grid-based like these? If so, this is pretty straightforward.

You can just do this:

  1. Check to see if there’s anything to your right.
  2. If not, turn right 90 degrees and then walk forward 1 cell.
  3. If so:
    3a) Check to see if there’s anything in front of you
    3b) If not, walk forward 1 cell.
    3c) If so, turn left 90 degrees.
    Repeat.
    (This does require the character to start in a valid cell with a valid direction, but that should be easy.)
    You can write the above into a looping coroutine pretty easily, and then you just need to decide how to check for cells to your right and in front of you (maybe raycast, maybe checking against a grid, etc), how to turn, and how to walk 1 cell, all of which are fairly simple.

Thanks StarManta, I can say I’m new to this. But I used similiar technics, meaninglessly rotation operation sometimes did not work.

İn order to all direction boxes, I created front,left ,right and back child collider. And for this childs I also created script files for each talk with the character file. My other way I used just one collider for caharacter. and I numbered boxes with consecutive numbers. So,
if up_move==true {
right_box=inside_current_box-1
}
then I was checking collider trigger true or false.

Is there any different technic to check right without using child or if we use childs use just one script.