Distance3D

Note: This feature is for ZScript only.

double Distance3D (Actor other)

Usage

This returns the distance from the calling actor to other, including Z position (if Z difference is unwanted, Distance2D 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 to the other actor on all axes.

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() {
        if (target && Distance3D(target) < 128) { // if we are less than 128 units away
            // Code could go here to make the imp less aggressive when the target is close, for example
        }
        Super.Tick();
    }
    
}
This article is issued from Zdoom. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.