Vec2
A two dimensional vector.
Properties
x
- doubley
- double
Methods
Vec2:new(x, y)
Vec2:new(x, y)
x
- What to set x toy
- What to set y to
Constructs a new Vec2 with the provided x and y.
Example:
local screenPosition = Vec2:new(200, 200)
length()
length()
Returns the length of the Vec2
Example:
local vec = Vec2:new(200, 200)
print("The vector has a length of " .. vecL:length())
distanceTo(otherVec2)
distanceTo(otherVec2)
otherVec2
- A different Vec2
Returns the distance from this vector to the otherVec2
Example:
local vecA = Vec2:new(200, 200)
local vecB = Vec2:new(400, 690)
print("Distance from vecA to vecB: " .. vecA:distanceTo(vecB))
angleTo(otherVec2)
angleTo(otherVec2)
otherVec2
- A different Vec2
Returns the angle to the otherVec2
Example:
local vecA = Vec2:new(1, 0)
local vecB = Vec2:new(0, 1)
print("Angle between vecA and vecB: " .. vecA:angleTo(vecB)) --prints 90
normalized()
normalized()
Returns this vector but normalized (that is with length 1)
Example:
local vecA = Vec2:new(20, 10)
print("vecA normalized: " .. vecA:normalized():toString()) --prints (0.8944, 0.4472)
scale(scalar)
scale(scalar)
scalar
- By how much you want to scale the vector
Returns a scaled version of this vector
Example:
local vecA = Vec2:new(20, 10)
print("vecA scaled by 2: " .. vecA:scale(2):toString()) --prints (40, 20)
toString()
toString()
Returns a string representation of the Vec2
Example:
local vecA = Vec2:new(20, 10)
print("vecA: " .. vecA:toString()) --prints (20, 10)
Last updated