Lua API
  • 🔎Overview
  • Introduction
    • 🚀Creating scripts
      • 🧠First Steps
      • 🖥️Adding UI
      • 📚Creating Libraries
  • API
    • 🌐Global Functions
    • ⚙️Instances
      • 🔢Math
      • ☎️Events
        • event_t
      • 🎮Game
        • global_vars_t
        • cengine_client
          • cnet_chan
        • ccsgo_input
        • cinput_system
        • cgame_ui_funcs
        • ccvar
          • convar
      • 🕹️Mods
        • events_t
      • ✏️Draw
        • ⚙️Types
          • ⚙️rect
          • ⚙️vec2
          • ⚙️color
          • ⚙️accessor
        • 🖥️Adapter
        • ✏️Layer
          • outline_mode
          • rounding
          • glow_parts
          • text_params
            • text_alignment
          • shadow_dir
          • command
            • render_mode
        • 🖼️Managed
          • 🖼️texture
            • svg_texture
            • animated_texture
          • 🖼️shader
          • ™️font_base
            • font
            • font_gdi
            • glyph_t
            • font_flags
      • 🙋Entities
        • entity_list_t
          • entity_entry_t
        • base_entity
          • schema_accessor_t
          • cs2_weapon_base_gun
          • cs2_player_pawn
          • cs2_player_controller
          • cs2_weapon_base
          • cs2_grenade_projectile
        • ccsweapon_base_vdata
          • cfiring_mode
        • chandle
        • csweapon_mode
        • csweapon_type
        • weapon_id
        • csweapon_category
        • observer_mode_t
      • 🖥️Gui
        • ⚙️Types
          • ⚙️bits
          • ⚙️control_id
        • context
          • user_t
        • context_input
          • mouse_button
        • notification_system
          • notification
        • control
          • control_type
          • value_param
          • checkbox
          • slider
          • label
          • selectable
          • button
          • color_picker
          • spacer
          • text_input
          • combo_box
          • image
        • container
          • control_container
            • layout
            • group
      • ⚙️Utils
    • ⚙️Types
      • ⚙️ptr
      • ⚙️ref_holder_t
      • ⚙️vector
      • ⚙️vector4d
      • 🎮veccolor
      • 🎮color
      • 🎮cview_setup
      • 🎮cuser_cmd
      • 🎮game_event_t
    • 🟰Enums
      • 🟰client_frame_stage
      • 🟰input_bit_mask
Powered by GitBook

© 2025 - FATALITY

On this page
  • x
  • y
  • z
  • __call
  • is_zero
  • dist
  • dist_sqr
  • dist_2d
  • dist_2d_sqr
  • cross
  • is_valid
  • length
  • length_sqr
  • length_2d
  • length_2d_sqr
  • dot
Export as PDF
  1. API
  2. Types

vector

This type is a common 3D vector (x, y, z).

This type supports operations, such as +, -, /, * and ==.

x

Type: float

X coordinate.

y

Type: float

Y coordinate.

z

Type: float

Z coordinate.


__call

Constructs a vector.

Arguments

1. Default vector (0, 0, 0).

None.

2. Single value.

Name

Type

Description

value

float

X and Y coordinates.

3. XYZ values.

Name

Type

Description

x

float

X coordinate.

y

float

Y coordinate.

z

float

Z coordinate.

Returns

Type

Description

vector

Vector.

Example

local vec = vector(5, 25, 12);

is_zero

Returns true if this vector is within tolerance range.

Arguments

Name

Type

Description

tolerance

float

Max allowed tolerance. Defaults to 0.01.

Returns

Type

Description

bool

true if ranges between -tolerance and tolerance.

Example

local vec = vector(0, 0.1, 0.5);
print(tostring(vec:is_zero(1))); -- will print 'true', because every value fits in the range of -1 and 1

dist

Returns distance to another vector.

Arguments

Name

Type

Description

other

vector

Vector to calculate distance against.

Returns

Type

Description

float

Distance to other vector.

Example

local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist(vec2)));

dist_sqr

Returns squared distance to another vector.

This method is de-facto faster than the non-squared variant. Use it, if you need extra performance.

Arguments

Name

Type

Description

other

vector

Vector to calculate distance against.

Returns

Type

Description

float

Squared distance to other vector.

Example

local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist_sqr(vec2)));

dist_2d

Returns 2D (only x and y values) distance to another vector.

Arguments

Name

Type

Description

other

vector

Vector to calculate distance against.

Returns

Type

Description

float

Distance to other vector.

Example

local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist_2d(vec2)));

dist_2d_sqr

Returns squared 2D (only x and y values) distance to another vector.

This method is de-facto faster than the non-squared variant. Use it, if you need extra performance.

Arguments

Name

Type

Description

other

vector

Vector to calculate distance against.

Returns

Type

Description

float

Squared distance to other vector.

Example

local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist_2d_sqr(vec2)));

cross

Returns a cross product to another vector.

Arguments

Name

Type

Description

other

vector

Vector to calculate cross product against.

Returns

Type

Description

vector

Cross product.

Example

local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
local cross = vec1:cross(vec2);

is_valid

Returns true if all values in this vector are finite.

Arguments

None.

Returns

Type

Description

bool

true if values are finite.

Example

local vec = vector(5, 1, 6);
if vec:is_valid() then
    -- ...
end

length

Returns length of this vector.

Arguments

None.

Returns

Type

Description

float

Length of this vector.

Example

local vec = vector(5, 1, 6);
local length = vec:length();

length_sqr

Returns squared length of this vector.

This method is de-facto faster than the non-squared variant. Use it, if you need extra performance.

Arguments

None.

Returns

Type

Description

float

Length of this vector.

Example

local vec = vector(5, 1, 6);
local length = vec:length_sqr();

length_2d

Returns 2D length of this vector.

Arguments

None.

Returns

Type

Description

float

Length of this vector.

Example

local vec = vector(5, 1, 6);
local length = vec:length_2d();

length_2d_sqr

Returns squared 2D length of this vector.

This method is de-facto faster than the non-squared variant. Use it, if you need extra performance.

Arguments

None.

Returns

Type

Description

float

Length of this vector.

Example

local vec = vector(5, 1, 6);
local length = vec:length_2d_sqr();

dot

Returns dot product of 2 vectors.

Arguments

Name

Type

Description

other

vector

Vector to calculate dot product against.

Returns

Type

Description

float

Dot product.

Example

local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
local dot = vec1:dot(vec2);
Previousref_holder_tNextvector4d

Last updated 3 months ago

⚙️
⚙️