Hi,
I checked your project and it seems issue is pretty easy to solve.
Whole issue is not connected with wrong collision detection, but more with rounding values.
When you use get_collision_point()
it will return exact position where collision happened. When you hit block from its side (left or right) position X will be set to X of block side. And now, because blocks are placed into grid that returned X will be always on boundary between 2 cells. It seems Godot in method world_to_map()
assume that full X value to be already next cell and that is why collision on right side are working fine, but on the left side doesn't work (because of that rounding always cell on the right of collision is returned by world_to_map()
)
Here is some image to illustrate that issue:
The same point is returned when you hit cell (1, 0) from left side and when you hit cell (0, 0) from the right side, but in first case it will work as expected since (1, 0) cell will be returned, however in second case the same cell (1, 0) will be returned, but you actually hit cell (0, 0).
I fixed that issue by altering returned value like that: var collisionPos = get_collision_point() - get_collision_normal() * 32
. I just subtract half of the tile size according to hit normal to assure position will be "somewhere inside cell" instead of the border area which may cause rounding issues.