Vec3
A three dimensional vector.
Properties
x
- doubley
- doublez
- double
Methods
Vec3:new(x, y, z)
Vec3:new(x, y, z)
x
- What to set x toy
- What to set y toz
- What to set z to
Constructs a new Vec3 with the provided x, y and z.
Example:
local worldPosition = Vec3:new(100, 200, 300)
length()
length()
Returns the length of the Vec3
Example:
local vec = Vec3:new(200, 200, 100)
print("The vector has a length of " .. vecL:length())
distanceTo(otherVec3)
distanceTo(otherVec3)
otherVec3
- A different Vec3
Returns the distance from this vector to the otherVec3
Example:
local vecA = Vec3:new(200, 200, 20)
local vecB = Vec3:new(400, 690, 1000)
print("Distance from vecA to vecB: " .. vecA:distanceTo(vecB))
distanceTo2D(otherVec3)
distanceTo2D(otherVec3)
otherVec3
- A different Vec3
Returns the 2D distance from this vector to the otherVec3
Example:
local vecA = Vec2:new(1, 0)
local vecB = Vec2:new(0, 1)
print("2D Distance from vecA to vecB: " .. vecA:distanceTo2D(vecB))
getXYAngle()
getXYAngle()
Returns the angle which this vector is pointing at in the XY-Plane.
Example:
local vecA = Vec2:new(1, 1, 0)
print("vecA angle: " .. vecA:getXYAngle()) -- prints 45.0
normalize360()
normalize360()
Returns a new Vec3 where all components are normalized between 0 and 360. Useful when working with viewangles.
Example:
local vecA = Vec2:new(1, 1, 0)
print("vecA angle: " .. vecA:getXYAngle()) -- prints 45.0
normalized()
normalized()
Returns this vector but normalized (that is with length 1)
Example:
local vecA = Vec3:new(20, 10, 10)
print("vecA normalized: " .. vecA:normalized():toString())
-- prints vecA normalized: (+0.81649661, +0.40824831, +0.40824831)
scale(scalar)
scale(scalar)
scalar
- By how much you want to scale the vector
Returns a scaled version of this vector
Example:
local vecA = Vec3:new(20, 10, 5)
print("vecA scaled by 2: " .. vecA:scale(2):toString()) --prints (40, 20, 10)
screenPosition()
screenPosition()
Returns a Vec2 of where this Vec3 would be drawn on screen if it was a world position.
Example:
local closest = engine.getClosestPlayer().lerpOrigin
print("closest player head screen pos: " .. closest:screenPosition():toString())
toVec2()
toVec2()
Returns the first 2 components of this vector as a Vec2
Example:
local vecA = Vec3:new(20, 10, 5)
local vecA2D = vecA:toVec2()
print("vecA2D : " .. vecA2D:toString()) --prints (20, 10)
toString()
toString()
Returns a string representation of the Vec3
Example:
local vecA = Vec3:new(20, 10, 5)
print("vecA: " .. vecA:toString()) --prints (20, 10, 5)
Last updated