align items on a 3d grid

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

Hello there! I am trying to make a card game, and I want to drag and drop the card on a gameboard (rigidbody). How could I use a grid so the cards will not overlap on the gameboard and only spawn in certain positions?

This is the code that I am using:

func place():
var rayOrigin = Vector3()
var rayEnd = Vector3()
var cardbase = preload("res://Cards/CardBase.tscn")
var card = preload("res://Cards/3dcard.tscn")
var cardscript = preload("res://Cards/3dcard.gd")
var camera = get_tree().get_root().find_node("Camera", true, false)
if Input.is_action_just_released("leftclick") && cardinhand == 1 :
	var space_state = get_world().direct_space_state
	var mouse_position = get_viewport().get_mouse_position()
	rayOrigin = camera.project_ray_origin(mouse_position)
	rayEnd = rayOrigin + camera.project_ray_normal(mouse_position) * 2000000000
	var intersection = space_state.intersect_ray(rayOrigin, rayEnd)
	if not  intersection.empty(): 
		board = 1
		var addcard = card.instance()
		addcard.Cardname = cardnm
		add_child(addcard)
		addcard.translation = Vector3(intersection.position.x*1.01,intersection.position.y,intersection.position.z)
	cardinhand = 0

Also a screenshot with my nodes, is the grid correctly placed?

https://prnt.sc/ 1sjf7qz