Distance3D

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


Actor

native clearscope double Distance3D(Actor other) const

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

  • Actor 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 in its Tick() virtual override and halve its walking speed:

class WaryImp : DoomImp
{
    override void Tick() 
    {
        // if we are less than 128 units away:
        if (target && Distance3D(target) < 128) 
        {
            speed = default.speed * 0.5;
        }
        // otherwise:
        else
        {
            speed = default.speed;
        }
        Super.Tick();
    }     
}

See also