A_Chase

From ZDoom Wiki
Jump to: navigation, search

void A_Chase [(statelabel melee [, statelabel missile [, int flags]])]

Usage

This is the standard monster walking function which has to be used in the walking frames of a monster. Typically, it is used in an actor's "See" state or a custom equivalent. When called, actors usually change their directions to a strict 45 degree angle to give the effect of pursuit. This angle changes based on which direction the target is, no matter if the calling actor can see it or not.

Parameters

  • melee: The state to jump to when the monster decides to perform a melee attack. If this is null (ZScript only), 0, "" (empty string) (DECORATE only), or omitted, the monster will not be able to enter the melee state while chasing. Default is null ("Melee" if the function is called without parameters).
  • missile: The state to jump to when the monster decides to perform a ranged attack. If this is null (ZScript only), 0, "" (empty string) (DECORATE only), or omitted, the monster will not be able to enter the ranged state while chasing. Default is null ("Missile" if the function is called without parameters).
  • flags: Determines how the monster will behave when the function is called. Flags can be combined by using the | character between the constant names. Default is 0.
    • CHF_FASTCHASE – Actor will randomly attempt to strafe left or right around the target, like the "player bosses" in Hexen. Note that the calling actor will ignore their MaxDropOffHeight property when strafing, and so may strafe off cliffs or into pits from which they can not escape. Setting the NODROPOFF flag will prevent this from happening.
    • CHF_NOPLAYACTIVE – Actor will not play active sounds.
    • CHF_NIGHTMAREFAST – Actor will move twice as fast in Nightmare! difficulty setting or equivalent.
    • CHF_RESURRECT – Actor will enter the "Heal" state (if defined) upon encountering a revivable corpse, like the Arch-Vile.
    • CHF_DONTMOVE – Actor will not move.
    • CHF_NORANDOMTURN – Actor will not change its chasing angle to its target if its beyond a certain degree until something blocks the way (obstacle or wall).
    • CHF_NODIRECTIONTURN – Actor will not turn its angle to face the direction of travel.
    • CHF_NOPOSTATTACKTURN – Actor will not turn itself to its target after attacking.
    • CHF_STOPIFBLOCKED – Actor cannot turn away from obstacles blocking it. It will simply not move, but can still angle itself.
    • CHF_DONTTURN – Implies CHF_NORANDOMTURN, CHF_NOPOSTATTACKTURN and CHF_STOPIFBLOCKED.

Notes

  • This function is not subject to the same rules as other jump functions are in anonymous functions, and cannot be used inside if/else statements. A_Chase will perform its jump, no matter what circumstances apply.
  • Because this function and its variant have the capacity to put the actor into an attack state, they should not be used during the first tic of one of those states, as it may result in infinite recursion, which will usually manifest itself in the engine as a crash.

Examples

Here is an example of a new monster which uses the optional range attack as well as a melee attack if it is close to its target, like the Revenant.

actor Scurymonster
{
    Monster
    Height 20 // Default variables.
    Radius 16 // Default variables.
    Speed 10
    Missiletype "Cowmissile" // Not included in-game.
    Meleedamage 5
    States
    { 
    Spawn: 
        MONS A 10 A_Look
        Loop 
    See: 
        MONS ABCD 4 A_Chase("Meleeattack", "Cowattack")
        Loop 
    Cowattack: 
        MONS E 5 A_MissileAttack
        Goto See 
    Meleeattack: 
        MONS F 5 A_MeleeAttack
        Goto See
    }  
}