mirror of
https://github.com/Steffo99/hella-farm.git
synced 2025-02-16 09:03:58 +00:00
Create Hunter
behaviour, tracking Edible
bodies inside a certain area
This commit is contained in:
parent
1738ad0ed0
commit
630eb88f22
2 changed files with 35 additions and 0 deletions
24
behaviours/hunter.gd
Normal file
24
behaviours/hunter.gd
Normal file
|
@ -0,0 +1,24 @@
|
|||
extends Node2D
|
||||
class_name Hunter
|
||||
|
||||
|
||||
signal tracked(body: Node2D)
|
||||
signal untracked(body: Node2D)
|
||||
|
||||
|
||||
@export var tag: StringName
|
||||
|
||||
var possible_targets: Array = []
|
||||
|
||||
|
||||
func _on_detection_area_body_entered(body: Node2D) -> void:
|
||||
if body.find_children("Edible", "Edible", false, false):
|
||||
Log.p(self, "Tracking a new target: %s" % body)
|
||||
possible_targets.push_back(body)
|
||||
tracked.emit(body)
|
||||
|
||||
func _on_detection_area_body_exited(body: Node2D) -> void:
|
||||
if body in possible_targets:
|
||||
Log.p(self, "Not tracking anymore target: %s" % body)
|
||||
possible_targets.erase(body)
|
||||
untracked.emit(body)
|
11
behaviours/hunter.tscn
Normal file
11
behaviours/hunter.tscn
Normal file
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ctpn4hvkhxoi3"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_kxb8e"]
|
||||
radius = 100.0
|
||||
|
||||
[node name="Hunter" type="Node2D"]
|
||||
|
||||
[node name="DetectionArea" type="Area2D" parent="."]
|
||||
|
||||
[node name="Shape" type="CollisionShape2D" parent="DetectionArea"]
|
||||
shape = SubResource("CircleShape2D_kxb8e")
|
Loading…
Add table
Reference in a new issue