Hello, I'm trying to make a tiger AI that runs after the closest prey within range.
The tiger is running after preys and detecting them, however it is choosing to follow only the first prey within the preyGroup array.
I'd like to know how can I make it follow only the closest prey within range.
Here's the code:
for prey in preyGroup:
if prey !=null:
if global_position.distance_to(prey.global_position) < 280:
STATE = "HUNT"
currentTarget = prey
sprintModif = 4
wandering = false
else:
wanderState()
sprintModif = 1