fx: input extracted to own node

This commit is contained in:
djaidjai committed 2026-03-15 17:08:40 +01:00
1 parent 0af538ff3f
commit f4e5d13cf8
5 files changed
+41 -25

No files matched your search

@@ -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
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.