Attention | Topic was automatically imported from the old Question2Answer platform. | |
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)
add_child(room)
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.