Rotating a tile randomly

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

I have made a tile map autotiler and the texture gets repetitive when grouped together so I was wondering if there is a way to randomly rotate each tile at either 0, 90, 180, 270 degrees through code (gdscript).

Thanks in advance for any help!

:bust_in_silhouette: Reply From: rakkarage

you can use the three bool (flipX, flipY, and Blah) parameters in set_cell to setup any tile orientation

func _setRandomTile(map: TileMap, x: int, y: int, id: int, flipX: bool = false, flipY: bool = false, rot90: bool = false) -> void:
	map.set_cell(x, y, id, flipX, flipY, rot90, _randomTile(id))

func _randomTile(id: int) -> Vector2:
	var p := Vector2.ZERO
	var s := _tileSet.tile_get_region(id).size / _tileSet.autotile_get_size(id)
	var total := 0
	for y in range(s.y):
		for x in range(s.x):
			total += _tileSet.autotile_get_subtile_priority(id, Vector2(x, y))
	var selected :=
	var current := 0
	for y in range(s.y):
		for x in range(s.x):
			p = Vector2(x, y)
			current += _tileSet.autotile_get_subtile_priority(id, p)
			if current > selected:
				return p
	return p

func _setBackRandom(x: int, y: int, tile: int, flipX := false, flipY := false, rot90 := false) -> void:
	_setRandomTile(_back, x, y, tile, flipX, flipY, rot90)

func setFloor(x: int, y: int, wonky := false) -> void:
	var id
	match theme:
		0: id = Tile.Theme0Floor
		1: id = Tile.Theme1Floor
		2: id = Tile.Theme2Floor
		3: id = Tile.Theme3Floor
	var flipX := Random.nextBool() if wonky else false
	var flipY := Random.nextBool() if wonky else false
	var rot90 := Random.nextBool() if wonky else false
	_setBackRandom(x, y, id, flipX, flipY, rot90)

my wall tiles flip horizontally and sometimes (if wonky) my floor tiles flip and rotate in all directions creating new patterns