GodotComponentTest/scenes/HexGrid3DTest.gd

27 lines
742 B
GDScript

extends Spatial
onready var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
onready var HexTile3D = preload("res://scenes/HexTile3D.tscn")
func _ready():
print (hexgrid)
var num_tiles_x = 50
var num_tiles_z = 50
for i in range(-num_tiles_x / 2, num_tiles_x / 2):
for j in range (-num_tiles_z / 2, num_tiles_z / 2):
var pos = hexgrid.get_hex_center_from_offset(Vector2(i, j))
var tile = HexTile3D.instance()
var height = (sin(pos.y * 0.3) * sin(pos.y * 0.8) * 0.8 + cos ((pos.x) * 0.9) * 1.24) * 0.5 - 0.5
tile.transform.origin = Vector3(pos.x, height, pos.y)
add_child(tile)
var pos = hexgrid.get_hex_center3(Vector3(0, 0, 0))
print (pos)
var hex = hexgrid.get_hex_at(pos)
print (hex)
pass