Basics
Vec2, Vec3 and Color
The value types used for positions, sizes and colors.
Positions and sizes are Vec2 (screen) and Vec3 (world) values, and colors are Color values. All three have fields you can read and assign, methods, operators and tostring.
local a = Vec3(100, 200, 0)
local b = a + Vec3(0, 0, 50) * 2
print(b, a:distance(b)) --> Vec3(100.000, 200.000, 100.000) 100.0
local c = Color.hex("#4FC3F7")
c.a = 128
print(c) --> Color(79, 195, 247, 128)Any function that takes one of these also takes a plain table: {x = 1, y = 2} or {1, 2} for a Vec2, {r = 255, g = 0, b = 0} or {255, 0, 0} for a Color. Where a function takes a 3D position, an Agent works too and stands for where the agent is.
Vec2
Vec2(x, y)Vec2
A 2D vector.
Vec2.new(x, y) does the same. Missing components are 0.v.x, v.ynumber
The components. They can be assigned.
Component by component. Either side can be a number:
v * 2, 2 * v.a == bboolean
True when both are
Vec2 values with the same components.v:length()number
The vector's length.
v:normalized()Vec2
The same direction with length 1 (a zero vector stays zero).
v:dot(other)number
The dot product.
v:distance(other)number
The distance between two points.
v:lerp(other, t)Vec2
The point
t of the way from v to other (0 is v, 1 is other).v:copy()Vec2
A copy.
v:unpack()x, y
The components as two numbers.
v:to_vec3([z])Vec3
A
Vec3 with this x and y, and z (0 by default).Vec3
Everything Vec2 has, in three components, plus:
Vec3(x, y, z)Vec3
A 3D vector.
Vec3.new(x, y, z) does the same.v:length2d()number
The length of
x and y only, ignoring height.v:distance2d(other)number
The distance on the ground, ignoring height.
v:cross(other)Vec3
The cross product.
v:xy()Vec2
The
x and y components.Whether something at
pos turned to rotation (as agent:rotation() returns) faces target, within max_angle.Color
Components are integers from 0 to 255. Values outside that range are clamped.
Color(r, g, b [, a])Color
A color; alpha is 255 (opaque) by default.
Color.new and Color.rgb(r, g, b) do the same.A color from components between 0 and 1.
From a string,
"#RGB", "#RGBA", "#RRGGBB" or "#RRGGBBAA" (the # is optional), or from a number, 0xRRGGBB, with alpha as a separate argument (255 by default).c.r, c.g, c.b, c.ainteger
The components. They can be assigned.
c:with_alpha(a)Color
A copy with another alpha.
c:lerp(other, t)Color
A mix:
t of the way from c to other.c:copy()Color
A copy.
c:unpack()r, g, b, a
The components as four integers.
c:to_floats()r, g, b, a
The components as four numbers between 0 and 1.
Color constants
REDGREENBLUEWHITEBLACKYELLOWCYANMAGENTAGRAYORANGETRANSPARENTEach use of a constant such as Color.RED is a fresh value, so changing it never changes the constant.