Distance3DSquared
Jump to navigation
Jump to search
Note: This feature is for ZScript only. |
native clearscope double Distance3DSquared(Actor other) const
Usage
Returns the squared 3D distance from the calling actor to other (portal-aware). Essentially, this is the same as Distance3D, but Distance3D 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: **
.
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 && Distance3DSquared(target) < 128**2)
{
speed = default.speed * 0.5;
}
// otherwise:
else
{
speed = default.speed;
}
Super.Tick();
}
}