Thinking about it, I think the _draw
function takes coordinates relative to the object. In that case, you may need to transform the hitPos position by the global transform of the node so its position is in local space. Thankfully, there is a helpful function called to_local
that is great for this purpose:
func _draw():
draw_line(Vector2(), to_local(hitPos), drawColor)
I totally forgot about the to_local
function :sweat_smile:
Using to_local
should also handle node rotation, if I recall correctly.
Another thing to check that could be causing the issue is while raycasting to use global positions rather than local ones (global_position
rather than position
). I do not think that is causing the issue, but it might be something to check if the raycast does not return the expected results.