Godot 4 TileMap: rotate tiles?

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

I’m using TileMap in Godot 4 and can’t figure out how to rotate tiles placed on the TileMap.

This was possible in Godot 3.x and I wonder if that feature is gone? Is there any other way to achieve the same?

Thank you

I guess the Dev’s decided to go for another massive internet trolling again on this one

jonPS | 2023-01-10 17:56

:bust_in_silhouette: Reply From: epergo

Not sure if this is how you are supposed to do it but sharing it anyways:

In your tileset select the tile you want to flip, right click and select Create an Alternative Tile, click the alternative tile (they are in the right side of the tiles editor) now in the tile properties you have 2 new options under Rendering, they are flip_h and flip_v.

Changes to those properties will only affect the alternative tile, not the original.

I am currently also facing this issue as my tileset does not have any rotated tiles for walls/ceilings and I used to be able to just rotate the tiles. It seems like such a basic feature and I can’t believe it’s not present.
Unfortunately I find the alternative tiles extremely clunky to use so this is not a solution for me :frowning:
If anyone finds a way to actually rotate/flip tiles without using alternative tiles, please let me know :slight_smile:

Mastermori | 2022-12-19 22:30

:bust_in_silhouette: Reply From: Rauvnos

Click on your alternative tile, and look for the “Transpose” property. That will rotate it.

In short, pass a flip transform into the ‘alternative_tile’ property. Example shows adding a layer to a tilemap and rotating tiles based on a random tile type. I have 3 different dirt types I pick and rotate. Still playing around with this myself. Look up enums if you’re not familiar with how I’m using them. They are wildly useful and simple. They reduce the need to store/remember string names in your code. My TileSet is a single row so I only need to iterate through the columns (x).

func AddUnderLayer(tileMap : TileMap):
	for x in range(_mapWidth):
		for y in range(_mapHeight):
			var randomUnderTerrain : Enums.TerrainType = PickRandomUnderLayerTerrainType()
			var flip_h = randi_range(0, 1) == 1
			var flip_v = randi_range(0, 1) == 1
			var transpose = randi_range(0, 1) == 1
			var transform_flags = 0
			if flip_h:
				transform_flags |= TileSetAtlasSource.TRANSFORM_FLIP_H
			if flip_v:
				transform_flags |= TileSetAtlasSource.TRANSFORM_FLIP_V
			if transpose:
				transform_flags |= TileSetAtlasSource.TRANSFORM_TRANSPOSE
			tileMap.set_cell(Enums.TerrainLayer.Under, Vector2i(x, y), 0, Vector2i(randomUnderTerrain, 0), transform_flags)