Godot Version
4.3
Question
How do I select TileData for specific Atlas coords on a TileSet with a script?
My intention is to have a TIleMapLayer called HeightMask that uses a TileSet called HeightMap on every scene. My player script should be able to disable the physics collision on the specified tile when called to do so (based on the height value of the character at the time)
I can select it indirectly by getting cell tile data from a TileMapLayer and then change the physics shape as desired, but I don’t think this is a good final solution.
I think every function I need is in the documentation for TileSet, TileSetAtlasSource, TileSetSource and TileData, but it is confusing. I found a lot of documentation on how to do this for Godot 3 as it seemed simpler then, though I couldn’t reverese engineer this to Godot 4.
Scenario:
I am working with a 2.5d concept. To achieve this, I have a TileSet called HeightMap and I paint numbered tiles that have collision on them. I then use the players calculated current height to determine which collision shapes to turn off so I know which ledges I can jump over etc. I have no idea what I am doing, but I chose this way to prevent having to use too many collision layers
Current Setup
I have it “working”, but I have to select a tile painted with the heighmap to get the tile data and then I can remove and restore it’s physics shape as I want.
Every ledge has it’s own collision shape on physics layer 4 (Ledge). When I jump it disables collision with layer 4, but I don’t want to be able to use this to jump up a 2 high zone.
So I have the HeightMask with collision on physics layer 5. The player never turns off this collision layer, instead I determine the characters height and remove the physics objects on the specific tile. So if I am standing at height 1, and my jump height is one, when I jump it disables collision for HeightMask 1 and 2. This allows me to get up on height 2 from height of 1, but not from height of 0.
onready var current_tilemapheightmask = get_node(“…/…/HeightMask”) #Standard HeightMask tileset
tiledata_heightmask = current_tilemapheightmask.get_cell_tile_data(current_tilemapheightmask.local_to_map(player_node.get_position()))
On a jump:
tileddata_heightmask.set_collision_polygons_count(0, 0)
On landing:
tiledata_heightmask.set_collision_polygons_count(0,4)
tiledata_heightmask.set_collision_polygon_points(0, 0, PackedVector2Array([Vector2(-8,-8),Vector2(-8,8),Vector2(8,8),Vector2(8,-8)]))