Vec2
Vec2 is Simulo's built-in type for 2D vectors.
Constructor
To create a Vec2, use the global vec2(x, y)
function:
local vec = vec2(5, 5);
Arithmetic
Operators are implemented; you can use +
, -
, *
and /
on Vec2s.
Fields
.x
The X component of the Vec2. Is a number.
.y
The Y component of the Vec2. Is a number.
Functions
note
Make sure to use :function()
and not .function()
, or you'll get an error
:length()
Returns the length of the Vec2 as a number.
Example
local length = vec2(1, 1):length(); -- about 1.414
:normalize()
Returns a copy of the Vec2 with the length as 1
.
Example
local vec = vec2(123, 456):normalize();
print(vec:length()); -- 1
:rotate()
Returns a copy of the Vec2 rotated by a specified number of radians.
Example
local vec = vec2(0, 1):rotate(math.rad(90)); -- the vec is now vec2(1, 0)