Skip to content

vec3

3-dimensional vector structure

Math operators

This type supports following math operators: +, -, *, /, ==

Properties

Type Name Description
number x X position
number y Y position
number z Z position

Methods

new(x, y, z): vec3

Type Name Description Default
number x X position none
number y Y position none
number z Z position none

Constructor

1
local my_vec = vec3.new(25, 55, 15)

length(): number

Returns length of vector

1
2
local my_vec = vec3.new(12, 54, 23)
local my_length = my_vec:length()

length2d(): number

Returns 2D length of vector

1
2
local my_vec = vec3.new(12, 54, 23)
local my_length2d = my_vec:length2d()

world_to_screen(): number, number

Translates this vector into screen point (returns x, y on screen or -1, -1 if not on screen)

1
local x, y = entity_origin:world_to_screen()

cross(vec): number

Type Name Description Default
vec3 vec Other vector none

Returns cross product of 2 vectors

1
local cp = my_vec:cross(other_vec)

dot(other): number

Type Name Description Default
vec3/number other Other value none

Returns dot product of 2 vectors or vector and a float

1
local dp = my_vec:dot(other_vec)