Three vectors are shown in this diagram. The length of each vector's arrow is its magnitude. You can have
a vector with any number of dimensions. In this 2d picture, only two dimensions are used - x and y. In JK's
virtual world, a third dimesion - the z axis - is added to simulate the real world.
A 3d vector is expressed as three numbers - (x, y, z). Each number holds the vector's value on that axis. Because you can have vectors with different numbers of dimensions, you can't write all vectors as three numbers. The examples in this reference will use three numbers for all vectors, and the z axis will be left at zero if it is not used.
The blue vector in the above diagram can be expressed as '1 -1 0'. That's plus one unit on the x axis and minus one unit on the y axis. This gives the vector a direction of -45 degrees on the graph. The length of that vector is nearly 1.4.1
The length can be increased with no change in direction. This graph shows the blue vector from the above diagram.
The length has been increased to about 2.83, but the direction has not changed. The new vector is expressed as '-2 -2 0'.
Because vectors can represent different quantities (positions, velocity, acceleration), their unit is not consistent. The length of a velocity will be the speed of the velocity while the length of a position vector will be the JKU distance from the center of the virtual world.
Look at this diagram of a vector again. The vectors' displacement is the point
at the end of the arrow.
These dots represent positions in the virtual world. They are expressed the same as the vectors in the above diagram.
The '0 0 0' on the graph is the center of the world. If you imagine a line from
As you can see in those examples, positions are the same as displacement vectors. But remember this is only one type of vector. A position is a vector, but a vector is not always a position.
lvec=GetThingLook(player);
The variable, lvec, now holds the vector direction that the player is looking. You can use this variable in any vector parameter. For example:
SetThingLook(some_thing, lvec);
some_thing will be set to look in the direction held by lvec. The other way to write a vector is in this form: 'x y z'. You can use this anywhere a vector is called for. EG:
lvec='1 0 0';
Or,
SetThingLook(player, '1 0 0');
In that last example, the player was set to look straight down the x axis.
Sine, Cosine, and Quadrants
These are things you really should learn in Mathmatics. But I'll explain the stuff here anyway. These concepts are only needed for
VectorDot() and VectorCross(), so it's not a big deal if you skip this.
Two vectors form an angle and a plane.
This picture from VectorDot()'s description shows two vectors and the angle between them. Note that the angle starts at the +x black line and extends into the second quadrant(see below). Angles always start at the positive x line. Angles can extend positively or negatively. In this case, the angle is +120, but the same angle could be written as -240.
Notice that these two vectors form a 2d plane. No matter which way the vectors point, they will always
form a plane.
There are four quadrants on a graph. The results of the cosine and sine functions are negative
in some quadrants and positive in others. In the above example, the dot product was negative
because the angle ended in the second quadrant - in which cosine is negative.
Fully explaining sine and cosine is beyond the scope of this reference (and probably the author). So only the results of sine and cosine operations will be explained.
Sine returns a number from 0 to 1. The closer the end of the angle is to the y axis, the closer the returned number will
be to 1. As the VectorDot() picture shows, vector1 is placed on the positive side of the x axis. Wherever vector2 points
will be the end of the angle formed between the vectors. As the quadrant diagram shows, sine is negative in quadrants
3 and 4.
The closer the end of the angle is to the x axis, the higher the cosine will be. As shown in the quadrant graph, cosine
is negative in the second and third quadrants.
Vectors and Scalars
Scalars2 are quantities that have only magnitude - no direction. Scalars include time, mass, and speed. You can use
physics formulas like f=ma with vectors. Scale an acceleration vector by a mass and you will get a force vector. Here are some
other formulas to use:
Vector * Scalar = | Resultant |
---|---|
velocity * mass = | momentum |
acceleration * mass = | force |
velocity * time = | displacement |
acceleration * time = | velocity |
lookvector * speed = | velocity |
Of course, not all vector and scalar quantities that you can use are listed here. |