Portal aware distance between actor and arbitrary point?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
MartinHowe
Posts: 2081
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

Portal aware distance between actor and arbitrary point?

Post by MartinHowe »

All the distance functions seem to be based on the distance between two actors, usually where one is "self". It seems a bit silly to have to create a dummy actor (e.g., a mapspot) at a point, and then remove it, just to check the distance between that point and another actor. I can use the usual high school math equation, but that isn't portal aware.

Is there a portal-aware way to get the distance between an actor and an arbitrary point?
User avatar
phantombeta
Posts: 2179
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Portal aware distance between actor and arbitrary point?

Post by phantombeta »

There's portal-aware vector difference and offsetting functions in LevelLocals: Vec2Diff, Vec3Diff, Vec2Offset and Vec3Offset. (The top of the page explains how to use LevelLocals if you don't already know how to)
User avatar
MartinHowe
Posts: 2081
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

Re: Portal aware distance between actor and arbitrary point?

Post by MartinHowe »

phantombeta wrote: Sun Sep 21, 2025 7:45 am There's portal-aware vector difference and offsetting functions in LevelLocals: Vec2Diff, Vec3Diff, Vec2Offset and Vec3Offset. (The top of the page explains how to use LevelLocals if you don't already know how to)
Thanks very much :)

In case it helps anyone else:

Code: Select all

    Vector2 tv = (target.Pos.x, target.Pos.y);
    Vector2 pv = (newPos.x, newPos.y);
    let dist = Level.Vec2Diff(tv, pv).Length();
Post Reply

Return to “Scripting”