🌐Vector
Vector metatable
Fields
x
number
y
number
z
number
x [?]
number
(default: 0.0)
y [?]
number
(default: 0.0)
z [?]
number
(default: 0.0)
Create a new Vector.
:__tostring(): string
string
Overload for operator +
other
Overload for operator -
other
Overload for operator /
other
Overload for operator *
other
:__eq(other: Vector
): boolean
Vector
): boolean
Overload for operator ==
other
:Distance(other: Vector
): number
Vector
): number
other
Computes the distance from this vector to other.
:Distance2D(other: Vector
): number
Vector
): number
other
Computes the distance from this vector to other ignoring Z axis.
:Normalized(): Vector
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
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
Vector
): number
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
Vector
): number
vector
Dot Product of two vectors ignoring Z axis.
:Scaled(scale: number
): Vector
number
): Vector
scale
number
Returns this vector multiplied by the given number. The same as Vector * number
.
:Scale(scale: number
): nil
number
): nil
scale
number
Multiplies this vector by the given number. The same as Vector = Vector * number
.
:Length(): number
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
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
number
Returns the length of this vector ignoring Z axis.
:Length2DSqr(): number
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.
angle
Returns the new vector rotated counterclockwise by the given angle in the XY-plane, leaving the Z-axis unaffected.
angle
Rotates this vector counterclockwise by the given angle in the XY-plane, leaving the Z-axis unaffected.
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
.
vector
Returns cross product of two vectors. More Visualization
angle
distance
number
distance to move
Moves vector forward by a specified distance in the direction defined by a given Angle.
Example
:ToAngle(): Vector
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
Vec2
, boolean
Converts Vector to screen coordinate
:Get(): number
, number
, number
number
, number
, number
Returns x, y and z of this vector.
:GetX(): number
number
Returns x of this vector. The same as Vector.x.
:GetY(): number
number
Returns y of this vector. The same as Vector.y.
:GetZ(): number
number
Returns z of this vector. The same as Vector.z.
:SetX(value: number
): nil
number
): nil
value
number
Sets x. The same as Vector.x = value.
:SetY(value: number
): nil
number
): nil
value
number
Sets y. The same as Vector.y = value.
:SetZ(value: number
): nil
number
): nil
value
number
Sets z. The same as Vector.z = value.
Last updated