Hi all, this is my first post on forums for a few years so apologies if I miss anything critical.

I'm trying to get the mouse click position in worldspace coordinates when the viewport follows the player. So far it appears to remain fixed to the viewport coordinates. I have tried combinations of get_viewport().get_global_mouse_position(), event.position, event.global_position, etc as well as finding the difference between these vectors and the camera position with no success.

I'm needing a scalable solution that gets the Vector2 position of the mouse at various zooming, scaling, window sizes, etc. I assume that it is prebuilt in some Godot functions, but the solution has stalled the project for a couple weeks now.

Here is the code used in the GUI component:

extends Control

var selected_object = null
var selecting_SOI = null

onready var camera = $"../../../ZoomCam2D"

var waypoints = PoolVector2Array()


var popup_open = false

var edit_mode = false
var _last_mouse_pos
onready var line_2d = $"../../../../Line2D"

func _ready():
	Global.set ("hud",self)
	selected_object = $"../../../../Spaceship"
	selecting_SOI = $"../../../../Planet1"
	
	line_2d.clear_points()


func _input(event):

	if (edit_mode):
		if event is InputEventMouseButton and event.pressed:
			if event.button_index == BUTTON_LEFT:
				
				var actual_position = event.global_position - camera.position
				
				line_2d.add_point(actual_position)
				#_last_mouse_pos = event.position
				print("Pressed")

func _on_CheckButton_toggled(button_pressed):
	edit_mode = !edit_mode

Here is a GIF demonstration of the problem

Any information I'm missing just let me know! Cheers

Look for Input.global_mouse_position I think you can also do object.get_local_mouse_position to see it relative to object sorry didn't really read your code ill look at it but I hope this helps

Sorry wasn't on my computer, yeas so get_local_mouse_position and get_global_mouse_position are part of Canvas-item which is part of Node. Consider what you want to be drawing relative to and where. I want to draw in my Camera view so i would get the Local Position of the mouse within in the Camera View if that's supplying the largest view it would look like a global position on the screen but is relative to the view of the camera. Consider if i wanted to draw a line from the earth to your mouse i would do var earthCenter=Vector2(objectEarth.length/2,objectEarth.height/2)#The center of planet var mousePosition=cameraView.get_local_mouse_position#Position in object relative to it's origin draw line from earthCenter to mousePosition

Try Drawing it on paper or make a window you can drag around I do: on clicking the object mouseOffset = object.get_local_mouse_position on click and drag 1. object.rect_position = get_global_mouse_position - mouseOffset

Thank you! My understanding of canvas items was a little flawed, ending up getting the actual position using var actual_position = selected_object.position + camera.position + camera.get_local_mouse_position() line_2d.add_point(actual_position)

9 months later