Distance2D

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.

double Distance2D (Actor other)

Usage

This returns the distance from the calling actor to other, disregarding a difference in Z position (if Z difference is wanted, Distance3D can be used). Unlike something like (a.pos-b.pos).length(), this function is portal-sensitive.

Parameters

  • other: A pointer to the actor we are getting the distance to.

Return Value

The distance on an XY plane to the other actor.

Examples

This Imp will check if the target is under 128 units away (using the overriding of ZScript Virtual Functions), and if it is, execute code.

class WaryImp : DoomImp 
{

    override void Tick() 
    {
        Super.Tick();
        // if we are less than 128 units away:
        if (target && Distance2D(target) < 128) 
        {
            // Code could go here to make the imp less aggressive when the target is close, for example
        }
    }
}