🌐Vector

Vector metatable

Fields

Name
Type
Description

x

number

y

number

z

number

Vector(x [?]: number, y [?]: number, z [?]: number): Vector

Name
Type
Description

x [?]

number

(default: 0.0)

y [?]

number

(default: 0.0)

z [?]

number

(default: 0.0)

Create a new Vector.


:__tostring(): string


:__add(other: Vector|Vec2|number): Vector

Overload for operator +

Name
Type
Description

other


:__sub(other: Vector|Vec2|number): Vector

Overload for operator -

Name
Type
Description

other


:__div(other: Vector|Vec2|number): Vector

Overload for operator /

Name
Type
Description

other


:__mul(other: Vector|Vec2|number): Vector

Overload for operator *

Name
Type
Description

other


:__eq(other: Vector): boolean

Overload for operator ==

Name
Type
Description

other


:Distance(other: Vector): number

Name
Type
Description

other

Computes the distance from this vector to other.


:Distance2D(other: Vector): number

Name
Type
Description

other

Computes the distance from this vector to other ignoring Z axis.


:Normalized(): Vector

Returns this vector with a length of 1. When normalized, a vector keeps the same direction but its length is 1.0. Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use Vector:Normalize function.


:Normalize(): nil

Makes this vector have a length of 1. When normalized, a vector keeps the same direction but its length is 1.0. Note that this function will change the current vector. If you want to keep the current vector unchanged, use Vector:Normalized function.


:Dot(vector: Vector): number

Name
Type
Description

vector

Dot Product of two vectors. The dot product is a float value equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them. For normalized vectors Dot returns 1 if they point in exactly the same direction, -1 if they point in completely opposite directions and zero if the vectors are perpendicular. More


:Dot2D(vector: Vector): number

Name
Type
Description

vector

Dot Product of two vectors ignoring Z axis.


:Scaled(scale: number): Vector

Name
Type
Description

scale

number

Returns this vector multiplied by the given number. The same as Vector * number.


:Scale(scale: number): nil

Name
Type
Description

scale

number

Multiplies this vector by the given number. The same as Vector = Vector * number.


:Length(): number

Returns the length of this vector. The length of the vector is math.sqrt(x*x+y*y+z*z). If you only need to compare length of some vectors, you can compare squared magnitudes of them using LengthSqr (computing squared length is faster).


:LengthSqr(): number

Returns the squared length of this vector. This method is faster than Length because it avoids computing a square root. Use this method if you need to compare vectors.


:Length2D(): number

Returns the length of this vector ignoring Z axis.


:Length2DSqr(): number

Returns the squared length of this vector ignoring Z axis. This method is faster than Length2D because it avoids computing a square root. Use this method if you need to compare vectors.


:Rotated(angle: number|Angle): Vector

Name
Type
Description

angle

Returns the new vector rotated counterclockwise by the given angle in the XY-plane, leaving the Z-axis unaffected.


:Rotate(angle: number|Angle): nil

Name
Type
Description

angle

Rotates this vector counterclockwise by the given angle in the XY-plane, leaving the Z-axis unaffected.


:Lerp(b: Vector, t: number): Vector

Name
Type
Description

b

end value, returned when t = 1

t

number

value used to interpolate between a and b.

Returns linearly interpolated vector between two vectors. The value returned equals a + (b - a) * t (which can also be written a * (1-t) + b*t). When t = 0, a:Lerp(b, t) returns a. When t = 1, a:Lerp(b, t) returns b. When t = 0.5, a:Lerp(b, t) returns the point midway between a and b.


:Cross(vector: Vector): Vector

Name
Type
Description

vector

Returns cross product of two vectors. More Visualization


:MoveForward(angle: Angle, distance: number): Vector

Name
Type
Description

angle

distance

number

distance to move

Moves vector forward by a specified distance in the direction defined by a given Angle.

Example

-- entity position moved forward by 300
local pos = Entity.GetAbsOrigin(entity):MoveForward(Entity.GetRotation(entity), 300);

:ToAngle(): Vector

Converts Vector to Angle. See https://github.com/ValveSoftware/source-sdk-2013/blob/master/sp/src/mathlib/mathlib_base.cpp#L535


:ToScreen(): Vec2, boolean

Converts Vector to screen coordinate


:Get(): number, number, number

Returns x, y and z of this vector.


:GetX(): number

Returns x of this vector. The same as Vector.x.


:GetY(): number

Returns y of this vector. The same as Vector.y.


:GetZ(): number

Returns z of this vector. The same as Vector.z.


:SetX(value: number): nil

Name
Type
Description

value

number

Sets x. The same as Vector.x = value.


:SetY(value: number): nil

Name
Type
Description

value

number

Sets y. The same as Vector.y = value.


:SetZ(value: number): nil

Name
Type
Description

value

number

Sets z. The same as Vector.z = value.

Last updated