Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question search for the nearest destination

Discussion in 'Navigation' started by Zimaell, Jul 2, 2023.

  1. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    399
    the situation is as follows - a path is searched, point A is looking for a path to point B, for this it calculates the initial direction, for example, point A is at the top left and point B is at the bottom right, respectively, the vector (1f, 0 -1f) is obtained. if this point is inaccessible (blocked by some obstacle), then you need to look for other directions, and of course it is better to look for the optimal ones, that is, in this situation, you need to turn 45 degrees from the current direction, then -45, then 90 and -90, etc. .d. tell me how to do this?
    i tried like this
    Code (CSharp):
    1. private Quaternion[] ArrayDirRot = new Quaternion[8]{
    2.         Quaternion.Euler(0f, 0f, 0f),
    3.         Quaternion.Euler(0f, 45f, 0f),
    4.         Quaternion.Euler(0f, -45f, 0f),
    5.         Quaternion.Euler(0f, 90f, 0f),
    6.         Quaternion.Euler(0f, -90f, 0f),
    7.         Quaternion.Euler(0f, 135f, 0f),
    8.         Quaternion.Euler(0f, -135f, 0f),
    9.         Quaternion.Euler(0f, 180f, 0f)
    10.         };
    11. Vector3 dir = new Vector(1f, 0 -1f);
    12. for(int i = 0; i < ArrayDirRot.Length; ++i){
    13.      dirRot = ArrayDirRot[i] * dir;
    14.      searchPoint = pointStart + dirRot;
    but it doesn't work, I don't even understand how it "rotate"...
     
  2. androvisuals_unity

    androvisuals_unity

    Joined:
    Mar 23, 2020
    Posts:
    47
    This question is worded in a way which makes it very unclear.
    Are you using a NavAgent? The calculate path function ?
    How do you determine if a path is blocked by an obstacle?
    Better to break this down into smaller pieces.
     
  3. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    399
    Yes, already by this moment there is some kind of movement, I don’t use navmesh, the search is carried out by a castsphere, at the moment I still don’t understand how to implement several branches of the passage, the search for a path goes in the shortest way, and if there is a dead end, then the next available direction is selected ...
     
  4. androvisuals_unity

    androvisuals_unity

    Joined:
    Mar 23, 2020
    Posts:
    47
    I'd advise you to use either the built in navagent functionality of unity or to implement your own A* pathfinding algorithm.
    The problem your trying to solve has been tackled multiple times by a great deal of people.
     
  5. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    399
    yes, I understand that, now I’m solving this problem with the help of A *, only in this method I don’t like the fact that there are a lot of unnecessary movements, that is, the object is ahead and the waves (according to the A * method) in all directions and most likely this is a waste of time .
    I'm thinking of doing something like a rat looking for cheese in a maze, if you know what I mean...