Class "Vector"

Constructors

Vector () {: aria-label='Constructors' }

{: .abp .tooltip .badge }

void Vector ( float , float ) {: .copyable aria-label='Constructors' }

Functions

__add () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector __add ( Vector Right ) {: .copyable aria-label='Functions' }

Addition operators

__div () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector __div ( float Modifier ) {: .copyable aria-label='Functions' }

Division operators

__mul () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector __mul ( float Modifier ) {: .copyable aria-label='Functions' }

Multiplication operators

__sub () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector __sub ( Vector Right ) {: .copyable aria-label='Functions' }

Subtraction operators

__unm () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector __unm ( Vector Right ) {: .copyable aria-label='Functions' }

Subtraction operators

Clamp () {: aria-label='Functions' }

{: .abp .tooltip .badge }

void Clamp ( float MinX, float MinY, float MaxX, float MaxY ) {: .copyable aria-label='Functions' }

Clamps the vector based on left, top, right, bottom boundings. Doesn't keep direction

Clamped () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector Clamped ( float MinX, float MinY, float MaxX, float MaxY ) {: .copyable aria-label='Functions' }

Returns a clamped version of the vector.

Cross () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float Cross ( Vector second ) {: .copyable aria-label='Functions' }

Cross product this is the 2x2 matrix determinant or the resulting z value for their 3D versions with z=0

Distance () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float Distance ( Vector first, Vector second ) {: .copyable aria-label='Functions' }

Returns distance between two vectors

???- example "Example Code"

    local sqtDist = Vector(2,0):Distance(Vector(4,0))) --sqtDist = 2

DistanceSquared () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float DistanceSquared ( Vector first, Vector second ) {: .copyable aria-label='Functions' }

Returns squared distance between two vectors

???- example "Example Code"

    local sqtDist = Vector(2,0):DistanceSquared(Vector(4,0))) --sqtDist = 4

Dot () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float Dot ( Vector second ) {: .copyable aria-label='Functions' }

Dot product

FromAngle () {: aria-label='Functions' }

{: .static .tooltip .badge } {: .abp .tooltip .badge }

static Vector FromAngle ( float AngleDegrees ) {: .copyable aria-label='Functions' }

Build a Vector from an angle, returns a normalized vector. Angle 0 will result in (1, 0). Angle 90 will result in (0, 1).

???- example "Example Code" This code returns a vector that has a 45 degree angle

    local vec = Vector.FromAngle(45)) --vec is now Vector(0.70711,0.70711)

GetAngleDegrees () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float GetAngleDegrees ( ) {: .copyable aria-label='Functions' }

Returns the angle the vector is facing. The vector (1, 0) will be at 0 degrees. The vector (0, 1) will be at 90 degrees.

???- example "Example Code" This code returns the angle between two positions.

    local v1 = Vector(1,0) -- has angle 0.0
    local v2 = Vector(0,1) -- has angle 90.0
    local v3 = v2-v1 -- subtraction of 2 points is a vector connecting the two points
    print(v3:GetAngleDegrees()) -- prints 45.0

Length () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float Length ( ) {: .copyable aria-label='Functions' }

Returns the length of the vector

LengthSquared () {: aria-label='Functions' }

{: .abp .tooltip .badge }

float LengthSquared ( ) {: .copyable aria-label='Functions' }

Returns the length squared of the vector

Lerp () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector Lerp ( Vector first, Vector second, float t ) {: .copyable aria-label='Functions' }

Linear interpolation between two vectors. For t = 0 it returns the first Vector, for t = 1 it returns the second.

???- example "Alternate Function example" This function does the same as Lerp, but will not alter the input vectors.

    function Lerp(vec1, vec2, percent)
        return vec1 * (1 - percent) + vec2 * percent
    end

???- example "Example Code" This code will make v1 the vector 50% in between v1 and v2

    local v1 = Vector(0,0)
    local v2 = Vector(1,1)
    v1:Lerp(v2,0.5) -- v1 equals  Vector(0.5,0.5)  now

Normalize () {: aria-label='Functions' }

{: .abp .tooltip .badge }

void Normalize ( ) {: .copyable aria-label='Functions' }

Normalizes this vector

Normalized () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector Normalized ( ) {: .copyable aria-label='Functions' }

Returns a normalized version of this vector

Resize () {: aria-label='Functions' }

{: .abp .tooltip .badge }

void Resize ( float NewLength ) {: .copyable aria-label='Functions' }

Resizes the vector length.

Resized () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector Resized ( float NewLength ) {: .copyable aria-label='Functions' }

Returns a resized version of the vector.

Rotated () {: aria-label='Functions' }

{: .abp .tooltip .badge }

Vector Rotated ( float AngleDegrees ) {: .copyable aria-label='Functions' }

Returns a rotated version of the vector by AngleDegrees

Variables

X {: aria-label='Variables' }

{: .abp .tooltip .badge }

float X {: .copyable aria-label='Variables' }

Components of vector.

Y {: aria-label='Variables' }

{: .abp .tooltip .badge }

float Y {: .copyable aria-label='Variables' }

Last updated