Sprint 2 Technical Implementation - UQdeco2800/2022-studio-1 GitHub Wiki

Link back to the main page

Spawning of Ranged Enemy

The current implementation to spawn a ranged enemy can be found in NPCFactory(). Updated movement tasks were created to allow for better AI movement of enemies.

multiple AI tasks have been implemented into enemies, with one new task RangedMovementTask(). these tasks have been given priority values to ensure that the enemies fucntion correctly, with targeting the crystal first, and the main character second but with higher priority to all for the main character to kite enemies.

 private static Enemy createBaseRangeNPC(Entity target, Entity crystal) {
    //Vector2 RangeHitbox = new Vector2(2f, 1f);
    AITaskComponent aiComponent =
            new AITaskComponent()
                    .addTask(new WanderTask(new Vector2(3f, 3f), 2f))
                    .addTask(new RangedMovementTask(crystal, 10, 2f, 20f, 30f))
                    .addTask(new RangedMovementTask(target, 20, 2f, 3f, 5f));
    Enemy enemy =
            (Enemy) new Enemy()
                    .addComponent(new PhysicsComponent())
                    .addComponent(new PhysicsMovementComponent())
                    .addComponent(new ColliderComponent())
                    .addComponent(new HitboxComponent().setLayer(PhysicsLayer.RangeNPC))
                    .addComponent(new TouchAttackComponent(PhysicsLayer.RangeNPC))
                    .addComponent(aiComponent);

    PhysicsUtils.setScaledCollider(enemy, 0.9f, 0.4f);
    return enemy;
  }

improving ranged movement

This code is updated to stop the enemy when it gets to a certain range close to the main character, as ranged units will stay at a distance to attack.

private int getActivePriority() {
        float dst = getDistanceToTarget();
        if (dst <= range || !isTargetVisible()) {
            stop();
            return -1; // Stop and get ready to shoot
        } else if (dst > maxChaseDistance || !isTargetVisible()) {
            return -1; // Too far, stop chasing
        }
        return priority;
    }

Testing was completed and recorded below

Testing of updated AI task Priority and ranged enemy movement:

https://youtu.be/rGwg272r65w

Testing of pathfinding for ranged enemy movement:

https://www.youtube.com/watch?v=omrx_Rw0bsc