0 votes

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?

asked Jul 3 in Engine by glitso (12 points)

1 Answer

0 votes

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.

answered Jul 3 by Zylann (18,429 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.