0 votes

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 halfcellsize: = CellSize / 2

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

func calculatemapposition(gridposition: Vector3) -> Vector3:
return grid
position * CellSize + _halfcell_size

func creategrid():
for x in range(Size.x):
for z in range(Size.z):
var Plane
Tile = Plane.instance()
var grid
position = calculatemapposition(Vector3(x,0,z))
PlaneTile.setname(str(x) + "," + str(z))
addchild(PlaneTile)
PlaneTile.settranslation(gridposition)
yield(get
tree(),"idle_frame")

func ready():
create
grid()
}

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

Godot version 3.3
in Engine by (22 points)
edited by

1 Answer

+2 votes
Best answer

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

by (6,932 points)
selected by

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

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.

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 .

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

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 .

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.