Enemy Repositioning - UQcsse3200/2026-studio-2 GitHub Wiki

Introduction

Enemy repositioning ensures enemies are not overly abusive in their melee engagements with the player. After an attempted attack on the player, they will move a short distance away from the player (horizontally for non-flyers, 360 degrees for flyers).

How it works:

Enemy repositioning is implemented with Tasks on the AIComponent of a given enemy. Specifically, RepositionTask.java and FlyingRepositionTask.java (the only difference being FlyingRepositionTask does not have edge detection).

The task keeps its priority unset until the flag repositionRequired is set by a listener on "hitPlayer". (owner.getEntity().getEvents().addListener("hitPlayer", this::requestReposition);)

On high priority, reposition task supersedes wandering, chasing and attacking. It starts by creating a new EdgeDetectTask(0.3f), and calculates a vector away from the player, subsequently making a movement task.

The task remains active until an edge is reached or the movement finishes.