diff --git a/behaviours/move_towards_mouse.gd b/behaviours/move_towards_mouse.gd index 47772ec..cc61136 100644 --- a/behaviours/move_towards_mouse.gd +++ b/behaviours/move_towards_mouse.gd @@ -3,6 +3,7 @@ class_name MoveTowardsMouse signal move(movement: Vector2) +signal captured @export_range(-5, 5, 1) var speed := 1.0 @@ -10,6 +11,11 @@ signal move(movement: Vector2) @onready var viewport: Viewport = get_viewport() +enum State { STILL, CAPTURED } + +var state: State = State.CAPTURED + + func get_relative_mouse_position(): var viewport_position: Vector2 = viewport.position var viewport_mouse_position: Vector2 = viewport.get_mouse_position() @@ -19,7 +25,12 @@ func get_relative_mouse_position(): func _physics_process(delta: float) -> void: - var direction: Vector2 = position.direction_to(get_relative_mouse_position()) - var movement: Vector2 = direction * delta * speed - Log.p(self, "Moving: %s" % movement) - move.emit(movement) + match state: + State.CAPTURED: + var direction: Vector2 = position.direction_to(get_relative_mouse_position()) + var movement: Vector2 = direction * delta * speed + move.emit(movement) + +func _on_capture_area_mouse_entered() -> void: + state = State.CAPTURED + captured.emit() diff --git a/behaviours/move_towards_mouse.tscn b/behaviours/move_towards_mouse.tscn index 34878d4..0b5a2d5 100644 --- a/behaviours/move_towards_mouse.tscn +++ b/behaviours/move_towards_mouse.tscn @@ -1,6 +1,12 @@ -[gd_scene load_steps=2 format=3 uid="uid://bvrxvrjlo5130"] +[gd_scene load_steps=3 format=3 uid="uid://bvrxvrjlo5130"] [ext_resource type="Script" path="res://behaviours/move_towards_mouse.gd" id="1_nbja1"] +[ext_resource type="PackedScene" uid="uid://cbg5kgwxusvxf" path="res://behaviours/hover_detector.tscn" id="2_qru2e"] [node name="MoveTowardsMouse" type="Node2D"] script = ExtResource("1_nbja1") +speed = null + +[node name="CaptureArea" parent="." instance=ExtResource("2_qru2e")] + +[connection signal="mouse_entered" from="CaptureArea" to="." method="_on_trigger_area_mouse_entered"]