Skip to content

Traject Task

JSLLW edited this page Aug 29, 2023 · 3 revisions

Introduction

This task implements the movement of the projectiles. This class takes a destination param of Vector2 type which the projectiles would be heading toward.

Start moving towards the destination: start()

This method starts the movement of the projectile.

public void start() {
  super.start();
  movementTask = new MovementTask(destination);
  movementTask.create(owner);
  movementTask.start();
    
  this.owner.getEntity().getEvents().trigger("trajectStart");
}

Update the projectile movement: update()

This method updates the movement of the projectile.

public void update() {
  movementTask.setTarget(destination);
  movementTask.update();
  if (movementTask.getStatus() != Status.ACTIVE) {
    movementTask.start();
  }
}

Stop projectile movement: update()

This method stops the movement of the projectile.

public void stop() {
  super.stop();
  movementTask.stop();
}
Clone this wiki locally