• Godot Help
  • How to draw a UI rectangle, snapped to the edges of my tilemap tiles?

I'm making a top-down, Rimworld style colony builder and want to draw a selection rectangle. I can draw it on a UI CanvasItem but I don't know how to get the world position in relation to my moving and zooming camera.

I've tried drawing it straight to a Node2D in the world hierarchy and that works fine, but when I zoom in and out the line widths aren't constant.

    kittenkong
    hmm I haven't played rimworld. You mean getting screen position of certain Node2D then create UI in the position on said node on different CanvasLayer?

    To get screen position of Node2D in Godot 4 you can do node_2d.get_global_transform_with_canvas().origin, then in another layer you can draw your rectangle using two Node2D which you snap to your tilemap.

    This sounds really ugly, I wonder if there is prettier way to do this, like without creating Node2D. But I don't know how.
    There might be something here.