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