extends State
class_name BeeReturning

@onready var bee : Bee = get_parent().get_parent() as Bee # I think this is bad but I dont care it works
@onready var target : Beehive = get_tree().get_first_node_in_group("beehive")

func enter(_msg : Dictionary = {}) -> void:
	Log.pr("Returning to the hive")
	bee.bee_position_animation.play("Flying")

func update(_delta : float) -> void:
	pass


func physics_update(delta : float) -> void:
	if target:
		if bee.position.distance_to(target.position) > 3:

			bee.velocity = (target.get_global_position() - bee.position).normalized() * bee.speed * delta
			bee.move_and_collide(bee.velocity)
			bee.bee_body.look_at(target.position)

		else: 
			# Deposit the nectar and return it idle state 
			bee.deposit_nectar()
			state_transition.emit(self, "Idle")