terça-feira, 24 de maio de 2016

BP Compendium 2: Vectors


A vector is a structure that contains the values X, Y and Z. The use of vectors simplifies many things in 3D game programming. Vectors can be used to represent position, velocity, acceleration, distance, direction...

An Actor has a vector called Location that represents its current position in the 3D world.

Blueprints has some utility functions for vectors. The two most used are:
  • LengthThe length of a vector can be used to represent the distance between two points.
  • NormalizeCalculate the unit vector. The unit vector has a length equal to 1 and it is often used to indicate a direction.

Click to enlarge

In the example below an Actor is following a number of destination points. The vector "vDistance" is obtained from the subtraction between the current destination point and the current position of the Actor.

The length of the "vDistance" vector represents the distance remaining to the Actor to get to the current destination point. If this value is less than the value of the "MinimumDistance" variable then it means that the Actor arrived at the destination point and can now go to the next destination point.

Click to enlarge