A_ClearTarget

From ZDoom Wiki
Jump to navigation Jump to search

Actor

void A_ClearTarget()

Usage

Makes the calling actor forget about its target, sound target, and last target. You can call this before jumping back to a monster's idle states to make a monster "give up" trying to chase after its target after a while (for example, if it's too far away), after which it will resume searching for targets or doing whatever else is specified in its Spawn state sequence.

Examples

This version of the Imp will forget about its target every 20 seconds as long as it's alive. If its former target is out of its field of vision by that point, it'll stop chasing it and automatically return to its Spawn state sequence where it'll call {{function|A_Look}] as usual, trying to find a target again.

class ForgetfulImp : DoomImp
{
  uint forgetTimer;

  override void Tick()
  {
    Super.Tick();
    if (!isFrozen() && health > 0 && (GetAge() % TICRATE == 0))
    {
      forgetTimer++;
      if (forgetTimer >= 20)
      {
        A_ClearTarget();
        forgetTimer = 0;
      }
    }
  }
}

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of UZDoom. The most up-to-date version of this code can be found on UZDoom GitHub.
	void A_ClearTarget()
	{
		target = null;
		lastheard = null;
		lastenemy = null;
	}