diff --git a/behaviours/move_towards_mouse.gd b/behaviours/move_towards_mouse.gd index 14552b7..73f52eb 100644 --- a/behaviours/move_towards_mouse.gd +++ b/behaviours/move_towards_mouse.gd @@ -3,17 +3,19 @@ class_name MoveTowardsMouse signal move(movement: Vector2) +signal detached signal captured @export_range(-500, 500, 1) var speed: float = 100.0 +@export var can_detach: bool = false @onready var game := MainGame.get_ancestor(self) -enum State { STILL, CAPTURED } +enum State { DETACHED, CAPTURED } -var state: State = State.STILL +var state: State = State.DETACHED func get_relative_mouse_position(): @@ -32,3 +34,8 @@ func _physics_process(delta: float) -> void: func _on_capture_area_mouse_entered() -> void: state = State.CAPTURED captured.emit() + +func _on_capture_area_mouse_exited() -> void: + if can_detach: + state = State.DETACHED + detached.emit() diff --git a/behaviours/move_towards_mouse.tscn b/behaviours/move_towards_mouse.tscn index e22de55..ab15a6f 100644 --- a/behaviours/move_towards_mouse.tscn +++ b/behaviours/move_towards_mouse.tscn @@ -9,3 +9,4 @@ script = ExtResource("1_nbja1") [node name="CaptureArea" parent="." instance=ExtResource("2_qru2e")] [connection signal="mouse_entered" from="CaptureArea" to="." method="_on_capture_area_mouse_entered"] +[connection signal="mouse_exited" from="CaptureArea" to="." method="_on_capture_area_mouse_exited"]