3D hexgrid

Blitz3D Forums/Blitz3D Programming/3D hexgrid

RGF(Posted 2009) [#1]
I'm searching for ideas about creating a hexagonal grid system, in a 3d environment. A grid can only be occupied by one object (player, enemy, item, chest...). For example, player can only attack neighbouring grids, or catch objects from neighbouring grids. And enemies will not move and collide constantly, sliding into each other, as they can stand only on one grid.

After programming a combat system for an rpg diablo style, i've found gameplay is horrible due to chaos in collisions, moving enemies, colliding bullets etc...
And wondered this could be more ordered if using an hexagonal grid...

The question is: how could I create a 3d "floor" made of hexagonal tiles? Each of these tiles should have a unique identification, in order to know which one is occupied by an object.

Thanks


Pongo(Posted 2009) [#2]
Don't know if this helps any, but you can work with a hex grid the same as a rectangular grid. All you need to do is offset every-other row by half a unit. This results in a grid like this.




Now you can simply refer to each position in the same way you would in a regular grid.


6(Posted 2009) [#3]
This is a scaled down version of something i was using to create a hex grid. Just change the yTiles and xTiles constants to what you want:

Global ScreenWidth = 800
Global ScreenHeight = 600

Graphics3D ScreenWidth,ScreenHeight,32,2

Global LIGHT = CreateLight(1)
LightColor LIGHT,255,255,255
PositionEntity LIGHT,10,0,7
RotateEntity LIGHT, 90, 0, 0

Global TARGET = CreatePivot()
Global CAMERApivot = CreatePivot()
Global CAMERA = CreateCamera( CAMERApivot )
PositionEntity CAMERA, 0,10,-10

;Tile variables
Global yTiles = 20	;Number of tiles on the y axis
Global xTiles = 6	;Number of tiles on the x axis
Global totalTiles = yTiles * xTiles
length# = 1.2	;Length of the hexagon so we can calculate the spacing between tiles
C# = length
A# = Sin(30)*C
B# = Sin(60)*C

;Calculate tile positions
Dim coord#(totalTiles*2)
k=0
For i = 1 To yTiles
	For j = 1 To xTiles
		
		If (i Mod 2)  Then
			
			;store the center pixel	
			coord(k) = j*(B*2) + B
			k = k + 1 
			coord(k) = C + i*(A+C)
			k = k + 1 
		Else
			
			;store the center pixel	
			coord(k) = j*(B*2) + B + B
			k = k + 1 
			coord(k) = C + i*(A+C)
			k = k + 1 
		EndIf
	Next
Next 

;create a hexagon
hexagon = CreateCylinder(6)
ScaleEntity hexagon,1,0.3,1

;place the hexagons
j=0
For i = 0 To totalTiles-1
	tile = CopyEntity(hexagon)
	x# = coord(j)
	j=j+1
	z# = coord(j)
	j=j+1
	PositionEntity tile,x,0,z
Next
EntityAlpha hexagon,0 ; hide the orginal hexagon

;point camera to the first hexagon
PositionEntity CAMERApivot,coord(0),0,coord(1)
PointEntity CAMERA , CAMERApivot

;main loop
While Not KeyDown(1)
	Cls
	TurnEntity CAMERApivot, 0 , KeyDown(32) - KeyDown(30), 0  ;( Press A And D To rotate the cam)
	RenderWorld()
	Flip
Wend




Beaker(Posted 2009) [#4]
http://www.gamedev.net/reference/articles/article747.asp


jtassinari(Posted 2009) [#5]
hi, i have looked carefully to the exagon grid problem as i'm interested in it as well.

I haven't gone too far yet, but i could see a little mistake in the image shown above (immo) but i'f i'm wrong, please excuse me =)



assuming each square (exagon) sized by 2 unit, and each squere centered in (x,y)=(0,0)
the others should be distanziated by +-2 on x with y=0 and +-1 on x with t = +2 or -2

i hope this can be a usefull,

cheers,

jTassinari