Distance2DSquared
Jump to navigation
Jump to search
Note: This feature is for ZScript only. |
native clearscope double Distance2DSquared(Actor other) const
Usage
Returns the squared 2D distance from the calling actor to other (portal-aware). Essentially, this is the same as Distance2D, but Distance2D involves a square root calculation, whereas this version doesn't, making it a little less computationally expensive. As a result, it must be compared to the squared desired distance (see examples).
To square the desired value, use the ZScript power operator: **
.
For a 3D version, see Distance3DSquared.
Parameters
- Actor other
- A pointer to the actor we are getting the distance to.
Return Value
- double - the distance on an XY plane to the other actor, squared.
Examples
This Imp will check if the target is under 128 units away in its Tick override, and if it is, execute code.
class WaryImp : DoomImp
{
override void Tick()
{
Super.Tick();
// if we are less than 128 units away:
if (target && Distance2DSquared(target) < 128**2)
{
// Code could go here to make the imp less aggressive when the target is close, for example
}
}
}