Monday, 9 December 2013

Picking & Pathfinding

Couple of useful bits done this last week.  I got mouse picking of the regions in Unity using the Mesh Collider.  Each region generates it's own little mesh, which I don't use for drawing, but unity can use it for collision nicely.  For some reason the very first region, [0], doesn't want to be picked even though it's exactly the same as the rest..maybe it's shy.

I also go path finding up and running.  There's a good xna sample that I used as a basis and amended for my needs.  For a goal cost estimation, which you need for some search heuristics, I thought I'd look up and use the arc distance.  I'm getting pretty good at some calculations on spheres but every so often I'll seek out some formula and get a hell of a fright.  Look at this demonic utterance.

kill it with fire!
There's a simpler one below thank goodness.  I now know this is called the great circle distance. (+1 math to me).  I have three different search algorithms to pick from, best first, A* and breadth first.  Best first & A* work fine and are pretty similar, in some cases they won't get the optimal route as you can see below in the two images.  They work pretty well though and I can swap between algorithms...maybe even make it an unlock for a unit, as it gets better at exploring it can use the better search.  Something to keep in mind.  That is all.

A* vs breadth first.  Latter gets a shorter
path but needs a large search space.