Dog now watches target

This commit is contained in:
Dan 2024-05-06 14:37:38 +01:00
parent 4e2f51f50f
commit 4834ebdda8
3 changed files with 50 additions and 1 deletions

View file

@ -4,12 +4,36 @@ class_name Dog
@onready var death_box = $DeathBox
var acquired_target : Bee = null
var target_timer : float = 0.0
func _ready():
death_box.connect("body_entered", Callable(self, "_on_body_entered"))
death_box.connect("body_exited", Callable(self, "_on_body_exited"))
func _process(delta):
if acquired_target:
target_timer += delta
# Look at the target
rotation = lerp_angle(rotation, rotation + get_angle_to(acquired_target.global_position), 0.25)
if target_timer > 3.0:
# Kill the target!
acquired_target.die()
acquired_target = null
target_timer = 0.0
return
func _on_body_entered(area):
if area.is_in_group("bee"):
if !acquired_target:
Log.pr("Acquired target")
target_timer = 0.0
acquired_target = area
func _on_body_exited(area):
if area == acquired_target:
Log.pr("Lost target")
acquired_target = null
target_timer = 0.0