+3 votes

Hi All.
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).
Please help!

in Engine by (389 points)

Having the same problem. Did you find a fix?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.