How can i detect a TileMapLayer tile as 'One Way' using a raycast?

Yes indeed!

So to summarize…

The code @artinthecoder suggested did the trick:

if up_ray_cast.is_colliding():
	var collider = up_ray_cast.get_collider()
		
	var cell = collider.local_to_map(up_ray_cast.get_collision_point())
		
	var data = collider.get_cell_tile_data(cell)
		
	if data.is_collision_polygon_one_way(0, 0):
		print("Yes")
	else:
		print("No")

But there was an additional issue preventing it from working where, depending on the direction of the raycast, the value returned in:
var cell = collider.local_to_map(up_ray_cast.get_collision_point())
was incorrect as it was returning the cell below the cell we actually wanted to retrieve the data for when raycasting to test a tile above the player.

Simply adding
cell.y -= 1
After that line fixes the problem.

Thank you for your help @artinthecoder it’s very much appreciated :slight_smile:

1 Like