Generate sprite, but dont spawn in order and look messy

Godot Version

4.2

Question

can someone explain what am i do wrong with this?
capture-20240811-104353

and here is the code

@export var brick= preload(“res://brick.tscn”)

func _ready():
#this for getsize of the brick.
var test_brick = brick.instantiate() as Brick
add_child(test_brick)
var brick_size = test_brick.getsize()
test_brick.queue_free() #erase it after get size

var numrows = randi() % 5 #0 to 5	
    var numcolom = randi() % 6 +6 #6 to 12

for i in range(numrows):
	for j in range(numcolom):
		var copy = brick.instantiate() 
		copy.position = Vector2(j* brick_size.x, i * brick_size.y)
		add_child(copy)

What type of objects are the bricks? StaticBody2D? RigidBody2D?

If they’re solid objects, it’s possible they are colliding with each other (due to floating-point precision differences) and pushing each other away.

I’d suggest tinkering with their class and their collision masks so they cannot collide with each other. You might also consider implementing all the bricks as a single TileMap, if your bricks will always be aligned to a grid.