# Auto Face Target ## Description "Auto Face Target" is a QoL module for AzerothCore that automatically turns a player to face their current target when they attempt to cast a spell or use an ability that requires facing it, instead of the cast failing with "You are not facing your target." ## How it works The facing requirement (`SPELL_FAILED_UNIT_NOT_INFRONT`) is checked server-side in `Spell::CheckRange()`, before the client ever finds out the cast failed. This module hooks `ScriptMgr`'s `ValidateSpellAtCastSpellResult`, which fires just before that check, for every player-initiated cast. If the spell requires facing (`SPELL_FACING_FLAG_INFRONT`) and the player isn't currently facing their target, it snaps their facing towards it via `Unit::SetFacingTo()` - the same server-authoritative movement mechanism used for charges and knockbacks, so the stock client rotates the character with no client-side changes needed. Ground/location-targeted spells (Blizzard, Flare, and the like) are always left alone: they don't carry a resolved unit target at all, so the in-front check never applies to them in the first place, and forcing a turn toward the player's current target while they're aiming an AoE elsewhere would be wrong. ## Configuration See `conf/mod_auto_face_target.conf.dist` (rename to `mod_auto_face_target.conf` to use): ```ini AutoFaceTarget.Enable = 1 ``` ## Caveats - The correction is based on the player's currently selected target (`Unit::GetTarget()`), not the exact unit target of the specific spell being cast - the hook fires before the spell's own targets are resolved. This matches the common case (casting an ability at your current target) but could diverge for spells that explicitly target something other than your current selection. - Facing correction is issued via a movement spline, so casting while already moving could cause a brief stutter/rubber-band rather than a perfectly smooth turn. - The orientation correction is applied both via the movement spline (for the client-visible turn) and directly via `Unit::SetOrientation()` (so the in-front check that immediately follows this hook sees it right away). Without the direct set, the spline's effect isn't visible to that check until a later world tick, so the first cast attempt fails and needs a second press - found during in-game testing.