1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 08:04:23 +00:00
hella-farm/behaviours/tracker_tracker.gd

25 lines
801 B
GDScript3
Raw Normal View History

extends Tracker
class_name TrackerTracker
2024-04-19 02:30:35 +00:00
## Tracks [Tracker]s tracking the parent.
## Start [field tracking] a [Node2D] if it overlaps this [Area2D].
##
## Returns whether the body was added to the [field tracking] array.
func track_if_detected(body: Node2D) -> bool:
if overlaps_body(body):
return track(body)
return false
## Start [field tracking] a [Node2D] if it has a [Tracker] tracking this node or one of its ancestors.
##
## Returns whether the body was added to the [field tracking] array.
func track_if_tracked(body: Node2D) -> bool:
var act: bool = false
for tracker in body.find_children("*", "Tracker", true, false):
for ancestor in Traversal.get_ancestors(self): # Make more efficient, perhaps?
if ancestor in tracker.tracking:
act = track(body) or act
return act