Class FollowTask

All Implemented Interfaces:
PriorityTask, Task
Direct Known Subclasses:
TamedFollowTask

public class FollowTask extends ChaseTask
Follows a target entity until they get too far away or line of sight is lost
  • Constructor Details

    • FollowTask

      public FollowTask(Entity target, int priority, float viewDistance, float maxFollowDistance, float stoppingDistance, com.badlogic.gdx.math.Vector2 speed)
      Parameters:
      target - The entity to follow.
      priority - Task priority when following (0 when not following).
      viewDistance - Maximum distance from the entity at which following can start.
      maxFollowDistance - Maximum distance from the entity while following before giving up.
      stoppingDistance - The distance at which the entity stops following target.
      speed - The speed at which the entity follows the player.
    • FollowTask

      public FollowTask(Entity target, int priority, float viewDistance, float maxFollowDistance, float stoppingDistance, com.badlogic.gdx.math.Vector2 speed, boolean checkVisibility)
      Parameters:
      target - The entity to follow.
      priority - Task priority when following (0 when not following).
      viewDistance - Maximum distance from the entity at which following can start.
      maxFollowDistance - Maximum distance from the entity while following before giving up.
      stoppingDistance - The distance at which the entity stops following target.
      speed - The speed at which the entity follows the player.
      checkVisibility - Checks to see if the entity will consider obstacles in its path.
  • Method Details

    • start

      public void start()
      Starts the follow task by initializing the movement task and triggering the "followStart" event.
      Specified by:
      start in interface Task
      Overrides:
      start in class ChaseTask
    • update

      public void update()
      Updates the follow task by updating the movement task and stopping it if the entity is too close to the target.
      Specified by:
      update in interface Task
      Overrides:
      update in class ChaseTask
    • stop

      public void stop()
      Stops the follow task and the associated movement task, and triggers the "followStop" event.
      Specified by:
      stop in interface Task
      Overrides:
      stop in class ChaseTask
    • getInactivePriority

      protected int getInactivePriority()
      Determines the priority when the follow task is inactive based on the distance to the target, the visibility of the target entity, and the stopping distance.
      Overrides:
      getInactivePriority in class ChaseTask
      Returns:
      The inactive priority level or -1 if conditions are not met.