Monday, 18 November 2013

Which way is up?

Not a hugely fruitful week.  I spent some time looking at building ui elements in Unity and by extension how manage game state.  I followed the xna gamestate previously and that was nice, it allowed menus to transition on and off nicely making the user experience very pleasant.  There's a good example of how replicate a manager class in Unity where you create an empty game object and attach a manager, as a MonoBehaviour to it so I'll probably follow that as best I can.

After that I started thinking about how handle movement of a game unit.  I recall reading about how Blizzard made Diablo, they knew the player would spend most of their time clicking and attacking so they got that low level system up and running as quick as possible so they could refine it.

0-7 as directions. sampling different points.

Without a regular grid, either square or hex, it's a mildly tricky problem.  I want to able to use the numpad for a lot of the movement.  So I find North from the center point of each cell then calculate if the angle toward is within a certain range,45degrees. In image_A I'm just using the center point and there 0 would be numpad8 and so on.  This is not so good for most cases, so I also then looked at the midpoint of the edge which you can see the results in image_B.  So I calculate it twice to see what fits best, in some case the center point and edge midpoint overlap.  In image_C I add one more point to sample, which is one third between the edge and the center point of the cell.  Sadly you still end up with broken cases to deal with as in image_D.

That probably didn't make much sense to read.  The gist of it though is when you look at these irregular cells, in your mind you may look and think "well that's obviously north, that's east" etc but actually translating that into something you can encode is not straightforward.  My next approach will be to use some fuzzy logic to define what cells best fits what direction, and in certain cases add a small delay where you can toggle between two destination until the one you want is highlighted.

(Unity 4.3 is supposedly out but my 4.2.2 install says it's up to date...hmm).