Hex map movement problem

I’m working on a HoMM3 clone. I’ve got a hex map in form of a 2D array GameObject[,] hex = new GameObject[11,15] - 11 rows, 15 columns. Each hex has a script called Data attached to it which holds all it’s variables such as:

int y - row number

int x - column numer

bool obstacle - true if there is a terrain obstacle on that field

bool unit - true if any other unit stands on that field

bool canMove - true if active unit can move on that field

Each unit has a variable int speed which is unit’s movement speed in hexes. The problem is that units should not walk through other units and/or terrain obstacles, therefore they need to take longer paths. Pic related

alt text

Bear with the yellow highlight is the active monster, it has speed of 6 (as seen on his left side), but due to obstacles and units in north-east direction, he can’t go everywhere where he normally could, as he must take the longer route.

I need this script to change canMove variable of each Hex to true if active unit can move there.

More info:

  • The map is made of 3D gameobjects seen from above with Orthographic camera.

  • Each unit is an empty GameObject with it’s transform.position equal to transform.position of some Hex. It has a Plane child with the unit graphic.

  • I’m a C# man

cool enought, but I think you might be more/better help from a GameDeveloper forum such as:

Because your problem seems to me, more of a HEX-tile question than an actual Unity problem.

Hex tile movement is actually really simple:

if you are using a 2-d array to represent your tiles, and you are at tile position X,Y:

  • For square movement, just allow movement to (X+1,Y), (X-1,Y), (X,Y-1), (X,Y+1)
  • For hex movement just allow square movement and add: (X+1,Y+1), (X+1,Y-1)

To visualize why this works, simply shift every other row in a square grid half a space to the right (sorry I don’t have a picture off-hand)