# How To Block(Cost)Cells Based on the Terrain ready for A* path finding.

This topic is 2162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello All.

I would like to know how to work out the cost(or blocking) of each cell based on the terrain under the cell.
What I have is a grid of cells that overlay's the terrain. This I will use the A* algorithm on, but I need my cells set up based on the terrain.
I have a image that has the terrain and the grid overlyed onto the terrain with black dots to show what I mean.
Like I want the unit to walk up the ramp but not the cliff wall and on the ridge. But the ridge cell covers to whole of the top(See Image).
How to handle that sort of thing

##### Share on other sites
Calculate the slope between adjacent cells and then construct a formula to convert that slope into a movement cost. If the slope exceeds a certain value, the terrain is too steep and you can simply treat that cell as inaccessible.

In my current project I actually use the height difference, since the slope is deltaHeight/deltaX and deltaX is always 1 in my case. If it exceeds 1m, which corresponds to a 45 degree angle, I consider the cell to be inaccessible. Otherwise I multiply the current movement cost (calculated from factors such as the terrain underfoot) by 1 + deltaHeight. So at maximum it increases the movement cost of that tile by about 2x. That might not be realistic, but in testing its behaviour looks ok to me at the moment.

I should mention this is for creatures walking around. Slope affects vehicles much more severely I believe.

##### Share on other sites
Only one reply thanks.
You know the articles don't talk about setting up the cost and things.
[img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img]

##### Share on other sites
I'm sorry but I've seen way too many people acting as if this community owes them their time. This is FREE advice you're getting here, try to respect it a bit better. One reply is better than none.

His advice is sound. There is nothing wrong with it. Perhaps if you provided a little more information about your A* implementation then people would be able to tailor their answers better to your... ability... to comprehend.

I sounds to me like you're using an A* algorithm that was coded by someone else and you don't really understand how it works.

There is a great section on pathfinding here:
[url="http://theory.stanford.edu/~amitp/GameProgramming/"]http://theory.stanfo...ameProgramming/[/url]

Specifically to costs:
[url="http://theory.stanford.edu/~amitp/GameProgramming/MovementCosts.html"]http://theory.stanford.edu/~amitp/GameProgramming/MovementCosts.html[/url]

This is all I needed to write any pathfinders I've ever wanted.

##### Share on other sites
firstly I would like to thank you for your time and link. As I don't have that a* link in my collection of links on a*.

And I am part of this community as well and I hope I have helped others.

and No I have not stolen some ones A* algo. This will in fact be my second A* algo, My first one only used blocking or not blocking and it was on a smaller scale then the one
I need now as my cells are larger.

And a point for you in future is not to assume things, It will just make you and me look like an ass.

##### Share on other sites
now back to the problem at hand.
See the cliff at the left top the cell covers the top and the wall of the cliff how should I handle that sort of thing besides making smaller cells.
I want the units to go up there if they need to. thanks.

##### Share on other sites
[quote name='ankhd' timestamp='1329375737' post='4913588']
now back to the problem at hand.
See the cliff at the left top the cell covers the top and the wall of the cliff how should I handle that sort of thing besides making smaller cells.
I want the units to go up there if they need to. thanks.
[/quote]
If you want to deal with variable size pathfinding nodes then perhaps it's worth looking into using Quadtree nodes for pathfinding.

This isn't a completed algorithm (and it's not my video either) but this demonstrates the idea well: