fx: input extracted to own node

This commit is contained in:
2026-03-15 17:08:40 +01:00
parent 0af538ff3f
commit f4e5d13cf8
5 changed files with 41 additions and 25 deletions

View File

@@ -0,0 +1,29 @@
extends Node
var target = Vector2.ZERO # should be either Vector2 or Node2D
var updating: bool = false
var holding_lmb: bool = false
func _input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
# start tracking
target = owner.get_global_mouse_position()
updating = true
else:
# stop tracking
updating = false
func _process(delta):
if typeof(target) == TYPE_VECTOR2 and updating:
target = owner.get_global_mouse_position()
func get_target_position() -> Vector2:
if typeof(target) == TYPE_VECTOR2 or typeof(target) == TYPE_VECTOR3:
return target
elif "position" in target:
return target.position
else:
return Vector2.ZERO
target = Vector2.ZERO # reset target to a Vector2