I have a major problem. I'm using a grid map for a point-and-click RTS-type game. Based on what cell type the mouse detects, you can do certain things.
My level is a grid map. I am using the following code to capture where the ray from mouse collides with the grid map:
var ray_start = cam.project_ray_origin(mouse_pos)
var ray_end = ray_start + cam.project_ray_normal(m_pos) * ray_length
var space_state = get_world().direct_space_state
return space_state.intersect_ray(ray_start, ray_end, , collision_mask)
I am using
world_to_map to translate that collision point to the grid map coordinate. This is happening in process and I have a 'tile selector' mesh that gets its translation from the hovered grid map tile to 'highlight' the tile which is being hovered over.
PROBLEM: I don't know if it's the ray cast or
world_to_map but the result is super inconsistent. The detected collision point jitters between 2 floors, as if (it sometimes goes through the gridmap and collides with a non-existent object underneath, as if there was another floor 1 cell beneath the grid map.
I am using Godot 3.2. All my tiles are planes (although I tried with cubes and had the same problem).