# Best way to do turning as a cost/penalty

What’s the best way to implement having a grid graph with a penalty for turning? I’m planning on something with whole node movement, with a cost for turning from one square to the next. Similar to Space Hulk. GridUpdateGraph looked like the closest to what I want, but not quite.

Hi

This is something which cannot be implemented using the A* pathfinding algorithm without much cheating. Since the unit may approach a node from several different directions, one would have to create new nodes for each of those possible in-directions and connect them like the source node.
I am sorry to say that it is not especially easy to add this to the current system.

Before moving to the next tile, check if the character has to turn towards it. If yes, then check if he still has enough actionpoints or whatever to make the turn, and if yes, only then start the movement.

@Cherno

That only works for disabling turning in some situations. It is harder to apply turning as a penalty.

Hmm, maybe I can fudge it a bit more, I think I can get away with just having the cost function take the current orientation at the current node be taken into account for choosing next nodes. But I’m not sure how to do a custom cost function in your system.

Sorry, I should have been clearer. What I tried to suggest is that using a penalty system isn’t needed at all for turning, it can be done easily with a set Acion Point cost.

Then again, I suspect that I somehow misunderstood the OP O_o

Hmm, maybe I can fudge it a bit more, I think I can get away with just having the cost function take the current orientation at the current node be taken into account for choosing next nodes. But I'm not sure how to do a custom cost function in your system.

The thing is that the current orientation at a node is never known until the end of the algorithm. It cannot be used for that. The only way (without lots of special code) is to create a new node for every possible direction, and even that is quite messy.

You could try different heuristics (see A* Inspector → Heuristic) and a different heuristic scale. That can affect how much turning is done in the path.

I was able to hack up something using a custom framework. In a game where a model has 4 ‘movement points’, but turning costs a point, I can cheat a bit and only store one copy of the node, and only update it if the cost to reach the node is less than the cost of the current node (regardless of the direction, which I still store in the node). I think that will end up okay for my needs, as long as I provide the player the ability to manually turn in place in addition to my floodfill algorithm.