I’m using this free tileset: Fantasy Knight - Free Pixelart Animated Character by aamatniekss
And trying to implement all the animations for practice but this one really got me, I wanted to know how to detect my character is below a ledge so I can climb, but I didn’t want to manually make a object and put it in every ledge for that, is there a way to classify tiles in tilemaps for that detection or any other ideas?
I have a vague idea on how to do it. I’ll try to describe it, in case it helps:
Get the current global position of the player
Convert that global position to local position in the tile map layer and then get the map coordinate corresponding to that position using local_to_map()
Use that map coordinate to get the cell at the top of it, using get_neighbor_cell or by directly substracting one unit in the y axis. Get that cell using get_cell_tile_data or get_cell_atlas_coords, depending on what you choose in step 4.
Check what kind of cell it is. You can do that by checking its atlas ID or by using custom data. Maybe using custom data is a good way to classify tiles, as you said.
Based on the type of cell you get, do the logic you need.
Sorry if the explanation is not very good, its just a draft but I hope it helps! Ask if you have any doubts and I’ll try yo help
Hey, thank you I was actually able to detect if there’s a ledge but now I can’t figure out how to actually make the character climb it, I’d aprecciate any help, thank you.
func ledge():
var player_coords = ground_and_walls.local_to_map(global_position)
var top_left_cell = ground_and_walls.get_neighbor_cell(player_coords, 11)
var top_right_cell = ground_and_walls.get_neighbor_cell(player_coords, 15)
if ground_and_walls.get_cell_tile_data(top_left_cell) != null:
ledge_left = ground_and_walls.get_cell_tile_data(top_left_cell).get_custom_data("Ledge")
return top_left_cell
else:
ledge_left = false
if ground_and_walls.get_cell_tile_data(top_right_cell) != null:
ledge_right = ground_and_walls.get_cell_tile_data(top_right_cell).get_custom_data("Ledge")
return top_right_cell
else:
ledge_right = false
This is what figured how to do based on your instructions.
If you feel inclined to help me implement the wall hang or wall climb here’s the github of the project