A FaceTarget

A_FaceTarget is a code pointer used in the melee attack and attack animations for various monsters.

True to its name,  changes the angle of the monster it is called on to be facing in the direction of its target; if it has no target, it does nothing. This is important for attack animations so that the monster appears to observers be attacking the right thing, but for hitscanners it also sets the direction in which the monster shoots. This is not the case for projectile launchers where the aiming calculation is done separately.

If the target has invisibility (an example is due to the Partial invisibility, but also if the target is an invisible monster like the Spectre), a random offset is added to the angle so that the monster appears to be attacking the wrong location. This has different effects depending on the monster:


 * For melee attacks such as the Demon, it is entirely cosmetic. Although the monster may appear to be facing the wrong way there is no effect on the damage done to the target.
 * For hitscan attacks, the monster can end up facing and firing in the wrong direction (although the two will match)
 * For projectile launchers, the direction that the monster appears to be facing and the direction that the projectile is launched are independent. Both are independently fuzzed due to the invisibility effect.

Uses
The  code pointer appears in the following states in Doom's state table:

Internal calls
Many other code pointers also call A_FaceTarget internally:


 * A_PosAttack (Zombieman)
 * A_SPosAttack (Shotgun guy)
 * A_CPosAttack and A_CPosRefire (Heavy weapon dude)
 * A_TroopAttack (Imp)
 * A_SargAttack (Demon)
 * A_HeadAttack (Cacodemon)
 * A_SkullAttack (Lost Soul)
 * A_PainAttack (Pain Elemental)
 * A_SkelMissile, A_SkelWhoosh and A_SkelFist (Revenant)
 * A_VileTarget and A_VileAttack (Archvile)
 * A_FatRaise, A_FatAttack1, A_FatAttack2, A_FatAttack3
 * A_BspiAttack (Arachnotron)
 * A_SpidRefire (Spider Mastermind)
 * A_CyberAttack (Cyberdemon)

Example
The following is an example of how to set the  code pointer in a Dehacked file:

Pointer 21 (Frame 34) Codep Frame = 739

Or using BEX syntax:

[CODEPTR] Frame 1234 = FaceTarget