this post was submitted on 17 Sep 2024
1 points (100.0% liked)

Godot: The open source game engine

21 readers
1 users here now

A community for discussion and support in development with the Godot game engine.

founded 1 year ago
MODERATORS
 
This is an automated archive made by the Lemmit Bot.

The original was posted on /r/godot by /u/Kolkelight on 2024-09-17 00:44:31+00:00.


I follow this guide:

But how i can space the hexagons correctly?

I made each hex of different to find the problem... but changing "vert_space" and "horiz_space" isn't working....

I don't get it...

var hexagon_size : int = 50
var grid_width : int = 10
var grid_height : int = 10

#DRAW GRID
func _draw() -> void:
  var vert_space = hexagon_size * sqrt(3)/2
  var horiz_space = hexagon_size * 3/2
  for y in grid_width:
    var x_offset = (y % 2) * hexagon_size 
    for x in grid_height:
      var center_x = x * horiz_space + x_offset
      var center_y = y * vert_space
      _draw_hexagon(Vector2(center_x, center_y), hexagon_size, Color(randf(),randf(),randf()))

#DRAW HEX - THIS PART IS WORKING CORRECTLY
func _draw_hexagon(center : Vector2, radius: int, _color) -> void:
  var points = []
  for i in 6:
    var angle = PI * 2 / 6 * i
    var x = center.x + radius * cos(angle)
    var y = center.y + radius * sin(angle)
    points.append(Vector2(x, y))
  for i in 6:
    draw_line(points[i], points[(i + 1) % 6], _color)

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here