vector and Vector(float, float,float)

From NWN Lexicon
Jump to navigationJump to search

Note: Mediawiki doesn't allow both this to exist as lowercase (data type) and uppercase (function) variants so both are on this page at once.

vector Data Type

A vector is a structure of three floats, useful for defining positions and orientation vectors. To access the components of the vector, you can use the dot operator to get the x, y, and z components of the vector. The default value of a vector is [ 0.0, 0.0, 0.0 ] (or x = 0.0, y = 0.0, z = 0.0).

You define a vector by using the Vector command (see below for full details):

vector vVector = Vector(0.0, 0.0, 0.0);

You can alter individual parts of the vector later using the Dot Operator with x, y and z as parameters:

vector vVector = Vector(10.0, 10.0, 10.0);
vVector.x = 20.0; // Vector is now [20.0, 10.0, 1.0]

If you have a function declaration needing a default vector value you can use it in this way:

void MyFunction(vector vVector = [0.0,0.0,0.0]);


vector v = GetPosition(OBJECT_SELF) - GetPosition(oidTargetObject);
vector v2 = Vector(1.0f, 2.0f, 3.0f);
float fDistanceToTarget = sqrt(v.x * v.x + v.y * v.y + v.z * v.z);

Vector(float, float, float)

Creates a vector (position) from three points.

vector Vector(
    float fX = 0.0f,
    float fY = 0.0f,
    float fZ = 0.0f


x point of a triangle. (Default: 0.0f)
y point of a triangle. (Default: 0.0f)
z point of a triangle. (Default: 0.0f)


Returns a vector with the specified point values of fX, fY, and fZ.


A common use for this command is when creating a new location based on an objects location.

You can get an objects position vector by using GetPosition, or a position vector from a location using GetPositionFromLocation.

You can change the values of a set vector by using the dot operator.



See Also


VectorToAngle GetPosition GetPositionFromLocation

author: Charles Feduke, editor: Lilac Soul