find the center

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sorano Sakura

Hello , how are you doing ?
it’s took me some time but i managed to making grid from grid.res in 3d , using code in gdscript .
the informations i use from this video , and from GDQuest .

things looking okay , but i didn’t figure out how i make the grid in the center .
i tried some method , it didn’t work out .

{
extends Spatial

export var Size: = Vector3(8,0,8)

export var Cell_Size: = Vector3(2,0,2)

var _half_cell_size: = Cell_Size / 2

onready var Plane_: = preload(“res://TRPG/Plane.res”)

func calculate_map_position(grid_position: Vector3) → Vector3:
return grid_position * Cell_Size + _half_cell_size

func create_grid():
for x in range(Size.x):
for z in range(Size.z):
var Plane_Tile = Plane_.instance()
var grid_position = calculate_map_position(Vector3(x,0,z))
Plane_Tile.set_name(str(x) + “,” + str(z))
add_child(Plane_Tile)
Plane_Tile.set_translation(grid_position)
yield(get_tree(),“idle_frame”)

func _ready():
create_grid()
}

any advice ? so the grid become in the center .
thank you

:bust_in_silhouette: Reply From: Wakatta

As a beginner shooting for the stars straight away is definitely a bad idea.
Before building a rocket first learn how the engine works.

For the game genre you intend to make you will need path finding and aStar* works far faster and more accurately than navigation meshes. That said aStar* works best with positive numbers so offsetting the GridMap’s Translation by it’s own size is best.

Something you can achieve easily under transform in the Spatial section of the GridMap

The reason I suggest first to learn the engine is because GridMap already automatically does what you’re trying todo using world_to_map with a tile_set

Wakatta | 2021-05-15 11:30

To add to this: if this is your first ever game or first time using the Godot engine, I highly recommend creating a simplistic 2D game first so you can learn how to effectively use the tools provided by the engine.

timothybrentwood | 2021-05-15 13:00

thank you , i know about gridmap node , after 7 month from trying , i gave up on it , in my opinion gridmap is not the right choice for trpg game right now. it’s not like the tilemap in 2d at all .
so i decided to try make a grid map from gdscript and resource .

Sorano Sakura | 2021-05-17 08:09

Well aren’t you just a bundle of bad ideas.

Programming 101 Do not try to reinvent the wheel

Since you seem fixated on this I might as well help with your self torture.

Assuming by “center” you mean Vector3 (0, 0, 0)

for x in range(-Size.x / Cell_size.x, Size.x / Cell_size.x):
    for x in range(-Size.z / Cell_size.z, Size.z / Cell_size.z:
        var PlaneTile = Plane.instance()
        var gridposition = calculatemapposition(Vector3(x,0,z))

The above pseudo-code is just an assumption so let me know if it works

Wakatta | 2021-05-17 13:26

Yes , it’s work XD , thank you senpai .
now i feel kind of bad ignoring gridmap node cry in the corner .
thank you for the advice i appreciate it .

Sorano Sakura | 2021-05-17 17:04