+1 vote

Hi All and happy Easter!

I am using intersect_ray to capture collision points with my grid map (for point and click movement).
I want to detect gridmap tiles underneath the mouse. I've found a method called get_cell_item but cannot get it to work. hovered_point is returned by the intersect_ray method (i'm using position). I get invalid get index 'position' on base 'Dictionary'. I'm guessing this is referring to 'position' being a field in the intersect_ray dictionary and I am able to reference it in other parts of the code, but not here... How does get_cell_item really work?

The code:

func _physics_process(delta):
    var hovered_point = (raycast from mouse collision point).position
    var hovered_tile = gridmap.get_cell_item(hovered_point.x, hovered_point.y, hovered_point.z)
asked Apr 12 in Engine by Macryc (289 points)

1 Answer

0 votes
Best answer

Ok i think i've found what was wrong.
Intersect ray returns a 3d vector position alright, but the grid map makes no sense of it until that position is mapped onto the grid map itself. I found this method world_to_map and is seems to have done the trick:

var hovered_point = gridmap.world_to_map(raycast from mouse collision point).position)
answered Apr 12 by Macryc (289 points)
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.