+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)
in Engine by (506 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)
by (506 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 Frequently asked questions and 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 [email protected] with your username.