Vectors Explained (Scripting)

From AlliedModders Wiki
Jump to: navigation, search


Vectors in general tend to be rather confusing until they are explained. There are three different types you will see. Position Vectors, Velocity Vectors, and Angle Vectors. While in most basic cases you will probably only use one of these at a time, it doesn't hurt to know what the other two parameters are there for. Here is an example of the native 'TeleportEntity' to show you what it looks like:

native int TeleportEntity(int entity, const float origin[3], const float angles[3], const float velocity[3]);

Position Vector: The first Vector in this native, declared as origin[3], is the Position Vector. This simply tells us the entities absolute position in the world. The position vector could look something like {15.0, 30.0, 15.0} and this would mean the entity is 15 units along the X axis, 30 units along the Y axis, and 15 units along the Z axis.

Angles Vector: The second Vector in this native, declared as angles[3], is the Angle Vector. This specifies the rotation of an object. This vector would follow the format {pitch, yaw, roll} which modifies the angles at which the object is looking. 'Pitch' is the up & down angles, 'Yaw' is the left & right, and 'Roll' is the spin along the up/down/left/right vector.

Velocity Vector: The last Vector in the native is the Velocity Vector, declared as velocity[3] in the example. This vector tells the game where the object will be on the next frame. So on the next game frame, the Position Vector of this object will be the sum of the Position Vector and the Velocity Vector from our current frame.

Velocity Vectors

float vecOrigin[3], vecVelocity[3], vecResult[3];
AddVectors(vecOrigin, vecVelocity, vecResult);