SetXYZ

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

void SetXYZ (vector3 newpos)

Usage

This sets the actor's position without altering its blockmap links (and is NOT aware of portals)! This is good for, say, temporarily "imagining if" an actor were at a certain position for the sake of making specific calculations before restoring the actor's previous position in the same tic.

To set an actor's position permanently, you must either use SetOrigin or perform all required actions manually.

Manually moving actors

To set an actor's coordinates without using SetOrigin, you must call UnlinkFromWorld before calling SetXYZ, then call LinkToWorld and FindFloorCeiling, in that order, after calling SetXYZ.
Additionally, if you want the actor to snap to its new coordinates, you must also call ClearInterpolation after calling the aforementioned functions.

Examples

This function returns true if a given position has enough room for the caller's height:

bool CheckZat (Vector3 testPos) {
    vector3 oldPos = pos;
    SetXYZ (testPos);
         
    if (GetZAt (flags: GZF_CEILING) - GetZAt () < height) {
        SetXYZ (oldPos);
        return false;
    }

    SetXYZ (oldPos);
    return true;
}


This function is a ZScript version of SetOrigin:

void ZScriptSetOrigin (Vector3 newPos, bool moving) {
    LinkContext ctx;

    UnlinkFromWorld (ctx);
    SetXYZ (newPos);
    LinkToWorld (ctx);
    FindFloorCeiling (FFCF_ONLYSPAWNPOS);

    if (!moving)
        ClearInterpolation ();
}