Enemy Delayed Attack - UQcsse3200/2026-studio-2 GitHub Wiki
Overview
DelayedAttackTask() allows an enemy to perform melee attacks on a specified target layer. It is performed whenever a target is within the attack's hitbox, so long as no other tasks have a higher priority. The enemy will then wait until the cooldown is finished before spawning the attack hitbox. The attack is successful if the target collides with the hitbox, and the hitbox will disappear after a certain amount of time.
Usage
DelayedAttackTask() should be called inside of EnemyFactory.java for each enemy that has a melee attack.
The method takes four parameters:
| Parameter | Description |
|---|---|
target |
The entity to attack (player) |
priority |
The priority of the task |
attackRange |
The maximum range at which the attack can be performed |
attackDelay |
The time between beginning the attack task and creating the hitbox |
attackDamage |
The damage dealt to enemies |
attackKnockback |
The knockback dealt to entities |
When the task is called, the enemy will do nothing until the attackCooldown is finished, at which point it will spawn an attack entity (see Enemy Attack Factory) with the specified attackRange, attackDamage, and attackKnockback values. The attack will dissappear after one second. If any entity from the target's physics layer collides with the attack before it is removed, the entity will receive both damage and knockback.