Unreliable ray collisions using world_to_map()

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

In my player script I emit a signal when the mouse is pressed and a collision is detected with a RayCast2d collision point. This should remove the block that the RayCast2d being projected from the player collides with, but it seems to be inconsistent about what blocks it actually removes even some parts of the map it wont remove any blocks at all.
I didn’t notice anything amiss when I output all the relevant variables to the console. I’ve been hitting my head on a wall trying to diagnose this for hours at this point any help is appreciated.

Here’s the relevant code:

extends KinematicBody2D

signal hit(collision_point)

func mine():
	if mine_ray.is_colliding():
		var collision_point = mine_ray.get_collision_point()
		emit_signal("hit", collision_point)
		
func _physics_process(delta):

	if Input.is_action_pressed("ui_mine"):
		mine()

And in the script for the tilemap I have:

extends TileMap

func _on_Player_hit(collision_point):
	var tile = world_to_map(collision_point)
	set_cell(tile.x, tile.y, -1)

Thanks for your input!

:bust_in_silhouette: Reply From: Dipsy Wong

you can try visualizing the collision shape, there is an option under debug on the top bar

I just solved a similar issue, it is caused by the collision shapes of the tiles are colliding with each other and shift away

Unfortunately thats not the issue here, I can see the ray intersecting with a tile and yet when I click it doesnt always remove the expected one.

Cal_9000 | 2020-07-21 00:47