Vector2 to UI position

Godot Version

4.3.stable

Question

I need to open menu in place of LMB longpress. This is my setup:
image
There is timer connected to the mouse press, when it fires (and LMB is pressed), I’m getting position of mouse press and trying to open the menu there:

func _on_open_menu(pos: Vector2) -> void:
	menu_container.position ????
	menu_container.set_visible(!menu_container.is_visible())

menu_container is pointing to the VBoxContainer

The problem is that I do not know how to map global coordinate (that I get from mousepress event, as vector2d) to canvas layer, and open menu on mouse coursor.

I think this is what you want:

menu_container.position = menu_container.get_parent().get_local_mouse_position()

this assumes you’ve already added it to the scene tree.

1 Like

It kinda worked, but the placement was wrong. I was able to make this work by:

  1. Removing Node at the top. CanvasLayer item was the root of the scene
  2. Using below code:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.