godot 2d set position to mouse

To set the position of a 2D object in Godot using GDScript to the mouse position, you can use the following code:

func _process(delta):
    if Input.is_mouse_button_pressed(BUTTON_LEFT):
        var mouse_position = get_global_mouse_position()
        position = mouse_position

This code checks if the left mouse button is pressed and then retrieves the global mouse position using the get_global_mouse_position() function. Finally, it sets the position of the object to the mouse position using the position property.

Remember to attach this script to the 2D object you want to control. Let me know if you have any further questions.