+1 vote

Using raycasts to detect tiles with static bodies attached, I am trying to get a reference to the tilemap I am using through the collision of the raycast. Whenever it detects a tile, however I get the error, "Invalid type in function 'getnode' in base 'StaticBody2D (BasePlayer.gd)'. Cannot convert argument 1 from Object to NodePath."
The error points to the line of code "var collider = get
node(x.get_collider())" where x is a reference to the raycast.
I have almost identical code that works when used to detect objects outside of a tilemap, so it seems to be the tilemap that's the problem. Is there another easy way to get a reference to the tilemap through raycasting?

in Engine by (13 points)

1 Answer

+1 vote

According to the doc: https://docs.godotengine.org/en/3.1/classes/class_raycast.html#class-raycast-method-get-collider

get_collider() returns an Object, not a NodePath. That object is usually the body that the raycast detected. In the case of a tilemap, it will be the TileMap node itself.

by (29,036 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.