GetDistanceBetween(object, object)

From NWN Lexicon
Jump to navigationJump to search

The distance in meters between two objects

float GetDistanceBetween(
    object oObjectA,
    object oObjectB
);

Parameters

oObjectA
Any object represented in game.
oObjectB
Any object represented in game.

Description

Returns the distance in meters between two objects. Will return a float value of 0.0 if either of the two objects is INVALID.

However, it is important to note that this function does not consider whether the objects are in different areas; it will simply return the distance between the two objects as if they were in the same area.

Furthermore, if the objects are of invalid object types for this call (EG: The module object) this function will also return 0.0.

Remarks

This also takes into account the Z-axis, and thus isn't a direct measurement in only X and Y. To get a direct measurement (discounting the Z-axis) you must use Vectors.

Remember, the float value returned by this is in in-game meters. Each in-game tile is 10x10M.

Version

1.62

Example

// Conversation Action event. Get the distance between
// me (OBJECT_SELF) and the PC in conversation. If they are 
// within 5M (including any elevation) we will shout at them.

// NB: conversations can take place with PC's up to around 10M away

void main()
{
    // Get the PC
    object oPC = GetPCSpeaker();

    // Get the distance, and check it
    if (GetDistanceBetween(oPC, OBJECT_SELF) <= 5.0)
    {
        // Shout at them for being quite far away
        SpeakString("Hey, " + GetName(oPC) + " get nearer to me!");
    }
}

See Also

functions:  GetDistanceToObject

 author: John Shuell, editor: Jasperre, additional contributor(s): Ryan Hunt, Jasperre, everlast