A_JumpIfCloser

From ZDoom Wiki
Jump to navigation Jump to search

state A_JumpIfCloser (float distance, int offset [, bool noz])
state A_JumpIfCloser (float distance, str "state" [, bool noz])

Note: Jump functions perform differently inside of anonymous functions.

Usage

Jumps offset amount of states forward, or to the state label state, if the distance to the target is lower than the given value. For weapons and inventory, jumps if the target in the player's crosshair is closer than the given value.

NOTE - This function does not take into account the radius of either actor, so it's possible that either one wide actor or both being wide can prevent the jump from ever occurring. It's important that a blocking actor takes their own radius into account through means such as A_JumpIfCloser(radius + distance, "label") to help avoid such occurrences.

Parameters

  • distance - The distance an actor's target must be in order to jump. Distance is in units, similar to to the radius of A_Explode.
  • offset/state - The offset number of frames to jump forward, or the state label to jump to.
  • noz - If true, the function disables vertical distance checking. The default is false, which includes comparing the distance between how high the calling actor is to the target.

Examples

This makes the imps in Doom transform into archviles at random, but the transformation is guaranteed if you're close to them when they first see you.

ACTOR AngryImp : DoomImp replaces DoomImp
{
  States
  {
  See:
    TROO A 0 A_JumpIfCloser(196, "Transform")
    TROO AABBCCDD 3 A_Chase
    Loop
  Transform:
    TROO A 0 A_SpawnItemEx("Archvile", 0, 0, 0, 0, 0, 0, angle)
    Stop
  }
}

And this makes barrels self-aware and makes them go boom when you're in range:

ACTOR SmartBarrel : ExplosiveBarrel replaces ExplosiveBarrel
{
  +LOOKALLAROUND
  +AMBUSH
  +QUICKTORETALIATE
  States
  {
  Spawn:
    TNT1 A 0
    BAR1 AB 6 A_LookEx(LOF_NOSOUNDCHECK)
  See:
    BAR1 AB 6 A_JumpIfCloser(127, "Death")
    Goto Spawn
  }
}