I have a problem editing the cost of the path.

I have a problem editing the cost of the path.
goal : I want the character to follow the path I have created . after the end of the road, it will go to the destination by the fastest route finding algorithm.
How to do : I changed the penalty .

  • the nodes make the path I set penalty = 1 . other nodes of the map I set penalty = 1000000.
  • so if you calculate the cost, the character will follow the path with a penalty of =1 .
    result: the character still follows the shortest path through the cells with penalty = 1000000.
    desired : character walking on nodes with penalty = 1

Hi

Would you mind posting the code that you are using?

1 Like

What code do you mean? this is the code i use to handle the set penalty.
private void InitPointMap()
{
* List userBuildings = _userBuildingList.BuildingList;

  •         AstarPath.active.AddWorkItem((ctx =>
    
  •         {
    
  •             var gg = AstarPath.active.data.gridGraph;
    
  •             GraphNode[] nodes = gg.nodes;
    
  •             foreach (GraphNode node in nodes)
    
  •             {
    
  •                 node.Penalty = (uint)10000000;
    
  •             }
    
  •             for (int i = 0; i < userBuildings.Count; i++)
    
  •             {
    
  •                 int locationId = userBuildings[i].locationTileId;
    
  •                 BuildingOperation buildingOperation = Utils.GetBuildingOperation(locationId, _buildingFinder);
    
  •                 TilingTransform tilingTransform = Utils.GetTilingTransform(buildingOperation.BuildingObjId, _userBuildingList, _buildingFinder);
    
  •                 NNInfo nodePos = _aStar.GetNearest(tilingTransform.GetLocalPosition());
    
  •                 if(buildingOperation.BuildingId == 30101)
    
  •                 {
    
  •                     foreach (GraphNode node in nodes)
    
  •                     {
    
  •                         if (node.NodeIndex == nodePos.node.NodeIndex)
    
  •                             node.Penalty = (uint)0;
    
  •                     }
    
  •                 }
    
  •             }
    
  •         }));
      }
    

Hi . Please ask me what should i do with this line of code . Is it right ?