Skip to content

Vector

Fields


Name Type Ranges
x float X coordinates
y float Y coordinates
z float Z coordinates

Functions


Vector()

Return value

Name Type Description
vector Vector Returns a Vector ( 0, 0, 0 )
Example

1
2
3
4
local pos = Vector()
EngineClient:ExecuteCmd("echo x: " .. tostring(pos:x))
EngineClient:ExecuteCmd("echo y: " .. tostring(pos:y))
EngineClient:ExecuteCmd("echo z: " .. tostring(pos:z))
This code will create a Vector instance and then print out all the fields. This will create an invalid vector.


Vector()

Parameters

Parameter Type Description
x float X coordinates
y float Y coordinates
z float Z coordinates

Return value

Name Type Description
vector Vector Returns a Vector ( x, y, z )
Example

1
2
3
4
local pos = Vector(85,0,0)
EngineClient:ExecuteCmd("echo x: " .. tostring(pos:x))
EngineClient:ExecuteCmd("echo y: " .. tostring(pos:y))
EngineClient:ExecuteCmd("echo z: " .. tostring(pos:z))
This code will create a Vector instance and then print out all the fields.


IsValid()

Return value

Name Type Description
valid bool Returns true if the vector is valid, it's components aren't infinite values
Example

1
2
3
4
local pos = Vector()
if pos:IsValid() then
  EngineClient:ExecuteCmd("echo the vector is valid")
end
The body of the if statement will never be executed because the vector is invalid.


DistanceTo()

Parameters

Parameter Type Description
vector Vector The other vector

Return value

Name Type Description
distance float Returns the distance to the second vector
Example

1
2
3
local pos1 = Vector(85,640,120)
local pos2 = Vector(240, 940, 20)
EngineClient:ExecuteCmd("echo distance: " .. tostring(pos1:DistanceTo(pos2)))
This will print the distance between the two vectors.


Lenght()

Return value

Name Type Description
lenght float Returns the lenght of the vector
Example

1
2
local pos = Vector(85,640,120)
EngineClient:ExecuteCmd("echo lenght: " .. tostring(pos:Lenght())
This code will print the lenght of the vector.


DotProduct()

Parameters

Parameter Type Description
vector Vector The other vector

Return value

Name Type Description
lenght float Returns the dot product
Example

1
2
3
local pos1 = Vector(85,640,120)
local pos2 = Vector(120, 250, 650)
EngineClient:ExecuteCmd("echo dot: " .. tostring(pos1:DotProduct(pos2))
This code will print the dot product of the vectors.


CrossProduct()

Parameters

Parameter Type Description
vector Vector The other vector

Return value

Name Type Description
vector Vector Returns the cross product
Example

1
2
3
4
5
6
local pos1 = Vector(85,640,120)
local pos2 = Vector(120, 250, 650)
local cross = pos1:CrossProduct(pos2)
EngineClient:ExecuteCmd("echo cross x: " .. tostring(cross:x)
EngineClient:ExecuteCmd("echo cross y: " .. tostring(cross:y)
EngineClient:ExecuteCmd("echo cross z: " .. tostring(cross:z)
This code will print the cross product of the vectors.