Question by 
               Nis5l · Dec 28, 2019 at 04:47 PM · 
                pathfindingastar  
              
 
              A* finding nearest Object
Hey, i'm making a RTS game. I want to find the closest storage, but this wont work, because "remainingDistance" isn't getting refreshed. Does anyone know a fix?
  public void workOnTree()
     {
         Vector2 prevPos = transform.position;
         transform.position = workTree.getPos();
         Grid nearestStorage = null;
         float nearest = -1;
         foreach(Grid grid in mapGrid.getStorages())
         {
 
             aiPath.destination = grid.getPos();
             float newdist = aiPath.remainingDistance;
             
             if (newdist <= nearest || nearest == -1)
             {
                 nearestStorage = grid;
                 nearest = newdist;
             }
         }
 
         aiPath.destination = nearestStorage.getPos();
         transform.position = prevPos;
 
     }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
How to know which point that AI picked to move to? (A* Pathfinding) 0 Answers
A* pathfinging problem 0 Answers
Astar movement implementation not working properly 0 Answers
astar pathfinding with groups 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                