Your problem is in the assignment of target = posit
, here:
func_process(delta):
target = posit # <--- problem!
if Input.is_mouse_button_pressed(1):
target = get_global_mouse_position()
The posit
variable holds a single, static value as assigned in the onready
statement. In each frame (_process
), you first assign that static value to target
. Then, only if the mouse button is pressed, you assign the current mouse position to target
. In frames where the mouse is not pressed, the assignment of the single, static value is stored in target, but is not overwritten by the mouse position (because no mouse press) - which is why you get the original value back when the button isn't pressed.
I'm not sure why that first assignment is necessary (though, could depend on other code details you aren't showing). My first inclination would be to simply remove the target = posit
line in _process()
.