Encouraging downhill, Discouraging Uphill


Amazing asset, having a lot of fun playing with it so far. I’m trying to do some work to discourage the units from going up hill. At my first attempt I’ve just tried going with the most basic thing I could think of (add cost if the new node is above the previous one, remove cost if its below), however its not working. Am I at least on the right track with my thinking here? Eventually I’d like it to give score based on the angle from the previous path node (smooth downhill = low cost, steep down hill = higher cost).

Am aware this will slow things down quite a lot but am ok with this to ensure the best possible behaviour. Again, amazing asset, the local avoidance stuff makes me so happy to see.

		public void UpdateG (Path path) {
			g = parent.g + cost;
			g = parent.g + cost + path.GetTraversalCost(node) + heightDiffScore(node);

        private uint heightDiffScore(GraphNode node)
			return (uint)(node.position.y - parent.node.position.y) * 100000;


This is only possible by modifying the code of the package I’m afraid. Right now, it assumes all grid connections have the same cost in both directions. What you can do easily is to discourage them from walking on slopes altogether. This is done using the Angle Penalty which can be found under the advanced tab at the bottom of the grid graph settings (or if you are using the beta, by clicking the button to add a new grid graph rule). Would that work for you?

Thank you so much for getting back to me! I’m finding more luck with the Layered Grid Graph at the moment, I think right now its just easily wrap my head around it and customise it as I need to. I’ll see if I can dig out my receipt from my purchase (22nd April 2020 was my purchase but have changed my e-mail provider since then and can’t find it!) so i can get the beta. Thank you again

1 Like