Friday, 20 December 2013

Gazing at the night sky sphere

Tis the season for builds. I managed to finish a couple of bits of code off before heading home for Christmas.   Couple of things, I got a sky sphere up and working with just a simple dashed line.  Meant I could get rid of the blank plane I had just below the world.  I found I really needed something in the background to help with orientation.  That was just tricky enough that I might do a little write up of the process when I get back in the New Year.

Check out the build here!

Simple dashed lines and a horizon line
make up the sky sphere.

Also has some early work on the menus that I talked a little about last week.  They may not end up looking anywhere like they are right now but I wanted to test transitioning screens on and off and handling the input neatly.  So you can hit 'begin' and it will take you into the gameplay screen, which has a toolbar thing.  When you Escape out of there the camera neatly transitions into orbit and you're back in menus.  This is stuff I worked through in 'Last Chapter' so I'm pleased to be reusing the concepts.

I've been listening to 'Let It Go' from "Frozen" over, and over, and over again while I worked on that song.  I sometimes find it easier to code with music, looking forward to seeing the film.

It's obviously still very rough but I'm pretty happy with the way things are going.  It's slowly starting to shape into something more like a tangible game, and I'm getting more comfortable using Unity too so a nice end to the year.  I'll be away until January, so until then Merry Christmas and a Happy New Year everybody.

Monday, 16 December 2013

UI & game state management

I delved a little into the Unity GUI stuff this week.  I'm not entirely sure what I was expecting compared to XNA but I was surprised it wasn't a bit more...developed I guess.  I don't want to speak  too ill of Unity as the gui code is neat,  but when I think about how sophisticated 3D rendering in games is, font rendering seems primitive in comparison.  It's rendering textured quads, using a bunch of helper methods for positioning and cutting things up.  But if you wanted to scale up or down for different resolutions it can look like mud.    Compare this for example to the text on this web page which is very smooth and highly scale-able.  Games have so many different types/needs/platforms that it's probably not a fair comparison.  I'm just wondering how other engines handle it.

You can still get good results though, here I'm just picking a nice font with some useful coloring.   When drawing frames, you can see below I also get some glitching from the way it stretches the texture, I managed to fix it by altering the texture settings.  The borders don't seem to have tiling at the sides which is a bit of a bummer, I might end up needing to write a bunch of rectangle drawing.  All the other widgets like horizontal sliders, and in particular being able to add colors within the strings are a super helpful.

Unity stretching the ui texture instead of tiling them :(
I spent some time on the game state too.  This is the kind of code that I often get paralyzed by, it's like putting a puzzle together when you don't have a final image to work from.  I'm basing it off the xna gamestate stuff that I really like.  A particular point of puzzlement was the OnGUI() method in Unity.  This is where the UI stuff is both used and drawn, like clicking a GUI.button, but, you as it turns out don't want process other input here like key presses as it runs differently.  e.g. a single key press will fire multiple times instead of once.  And the reverse of that, you don't want mouse interaction on the GUI menus to also then interact with the 3d scene beneath it.    Then there's other stuff like where do you want to hold your list of game objects, how do you handle updating them, keeping track of what's picked, stuff like that I struggle with. 

I might try and get another build done for the end of the week but after that I'll be away for the holidays, so if I don't post again... Merry Christmas!

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. 

Monday, 2 December 2013

Numpad Forever

New build. After some difficulty and dragging ass I finally got a pretty good version of the keypad movement up and running in Unity.  I know when I play Civilization I favour the keyboard whenever I'm moving units around.  Moving units around is going to be what you spend much of your time doing in the game so I'm working on these lower level systems then building up from it.

Check out the build,  (Instruction on that page but mostly tap the numpad keys)

The rare ideal case - all 8 directions mapped.

Debug build in xna.  The fuzzy values in the top left
map how each node best fits each compass direction.

I'm still finding it much easier to tackle issues in XNA then move to Unity.  In the bottom image I have all the fuzzy logic values printed on screen.  In that particular image, I have to shuffle the mappings a little on the North East to the South as they don't fit neatly, seeing the problem and values all on screen was very helpful in tackling the problem.  The heuristics are broadly:

  1. what directions can these nodes fit?  (calculate fuzzy values for all 8 directions)
  2. where is the best/ideal fit?  (pick the best fuzzy value)
  3. are any nodes not mapped, if so try and slot in.  (use a less than perfect fuzzy value to find a spot) 
  4. failed to neatly plot so plan B.  (use a secondary plotting and allow the player to toggle between)

I'm starting to appreciate why turn based strategy game mostly adhere to nice uniform grids.  Though I've got it largely working quite well there are still a couple of edge cases.  Couple of stupid moment these last couple of weeks.  The directions where half broken at one point until I realized XNA uses a right handed coordinate system and Unity is left handed.  Second one was spending over an hour wondering why icons weren't changing/appearing/vanishing and getting null console messages when I was clearing adding the game object to the script! Then I realized I was adding them in the wrong place...doh.  That's going to be a recurring theme, I'm still a little clumsy using Unity.

Updated to Unity 4.3 with no issues. /hurray