Instantiated object snapped to grid

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

Im trying to instantiate an object with random location spawn snapped to grid but i dont know how. If anyone can help me i am really grateful for

	for i in range(num_levels):
	room = ROOMS[randi() % ROOMS.size()].instance()
	var x = rand_range(-320,640)
	var y = rand_range(-320,640) 
	room.position = room.position.snapped(Vector2(x,y) * 32 / 2) 

The instantiated room position is always (0,0) or (-0,0).
In the _ready() function i am using randomize() to give different results each time.

:bust_in_silhouette: Reply From: Gluon

If you are using 3.5 then there is a good tutorial on youtube going over all the aspects of grid based games link below

its a bit old now but will lead you through everything you need to know to do a grid based game. Hope this helps.