Pathfinder Cost Help
Jun 3, 2015 22:07:43 GMT
Post by CoffeeCake on Jun 3, 2015 22:07:43 GMT
I think I must be misunderstanding or misusing something. Trying to add cost to passing over mountains, my code for the latter part of HexGraph.ScanInternal is as follows:
Any help understanding the pathfinding cost system would be appreciated. Love your framework!
foreach (PointNode pn in nodes)
{
connections.Clear();
connectionCosts.Clear();
foreach (Vector3i v in HexNeighbors.neighbours)
{
Int3 offset = v.ToInt3();
Int3 pos = pn.position + offset;
if (nodeDictionary.ContainsKey(pos))
{
connections.Add(nodeDictionary[pos]);
Vector3i vec3i = new Vector3i(pos);
//if (World.instance.hexes[vec3i].terrainType.source.typeList.Contains(MHTerrain.Type.Mountains)){
if (World.instance.hexes[vec3i].terrainType.source.name == "Mountain"){
Debug.Log ("is mountain "+vec3i);
connectionCosts.Add(4);
//GameObject.Instantiate (GameManager.instance.debugSphere, HexCoordinates.HexToWorld3D (vec3i), Quaternion.identity);
}
else{
connectionCosts.Add(1);
}
}
}
pn.connections = connections.ToArray();
pn.connectionCosts = connectionCosts.ToArray();
}
With that GameObject.Instantiate uncommented, I can see that it is in fact spawning a sphere on each mountain, so it is correctly identifying the correct hexes, however, the Formation.GoTo does not avoid the mountains, as you can see in this screenshot, the unit should want to go north first, but doesn't, instead it goes right over the mountain:Any help understanding the pathfinding cost system would be appreciated. Love your framework!