Skip to content

Vector2

Fields


Name Type Ranges
x float X coordinates
y float Y coordinates

Functions


Vector2()

Return value

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

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


Vector2()

Parameters

Parameter Type Description
x float X coordinates
y float Y coordinates

Return value

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

1
2
3
local pos = Vector2(85,0)
EngineClient:ExecuteCmd("echo x: " .. tostring(pos:x))
EngineClient:ExecuteCmd("echo y: " .. tostring(pos:y))
This code will create a Vector2 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 = Vector2()
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 Vector2 The other vector

Return value

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

1
2
3
local pos1 = Vector2(85,640)
local pos2 = Vector2(240, 940)
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 = Vector2(85,640)
EngineClient:ExecuteCmd("echo lenght: " .. tostring(pos:Lenght())
This code will print the lenght of the vector.


DotProduct()

Parameters

Parameter Type Description
vector Vector2 The other vector

Return value

Name Type Description
lenght float Returns the dot product
Example

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


CrossProduct()

Parameters

Parameter Type Description
vector Vector2 The other vector

Return value

Name Type Description
vector Vector2 Returns the cross product
Example

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