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
  • calc_angleīģŋ
  • angle_normalizeīģŋ
  • approach_anglesīģŋ
  • edge_pointīģŋ
  • lerpīģŋ
  • vector_anglesīģŋ
  • world_to_screenīģŋ
  • clampīģŋ
  • remap_valīģŋ
  • remap_val_clampedīģŋ
  • vec2īģŋ
  • vec3īģŋ
Export as PDF
  1. API
  2. Instances

Math

Usage: math.{func}

This table extends the existing math table that is a part of Lua.

calc_angleīģŋ

Function

Calculates angles between 2 vectors.

Arguments

Name
Type
Description

src

Source vector.

dst

Destination vector.

Returns

Type
Description

Angles.

Example

local ang = math.calc_angle(vec1, vec2);

angle_normalizeīģŋ

Function

Normalizes an angle.

Arguments

Name
Type
Description

angle

float

Input angle.

Returns

Type
Description

float

Normalized angle.

Example

local norm = math.angle_normalize(560);

approach_anglesīģŋ

Function

Approaches an angle over time.

Arguments

Name
Type
Description

from

Start angle.

to

End angle.

speed

float

Approach speed.

Returns

Type
Description

Delta angle.

Example

local ang = math.approach_angles(from, to, 1.0 / game.global_vars.frametime);

edge_pointīģŋ

Function

Returns a point on the edge of a box.

Arguments

Name
Type
Description

mins

Box mins.

maxs

Box maxs.

dir

Point direction (angle).

radius

float

Area radius.

Returns

Type
Description

Point.

Example

local point = math.edge_point(mins, maxs, dir, 5);

lerpīģŋ

Function

Linear interpolation.

Arguments

Name
Type
Description

t1

float

Start value.

t2

float

End value.

progress

float

Interpolation amount.

Returns

Type

Description

float

Interpolated value.

Example

local mid = math.lerp(0, 100, 0.5);

vector_anglesīģŋ

Function

Calculates angles from a vector.

Arguments

Name
Type
Description

forward

Source vector.

up

Up vector. Defaults to nil.

Returns

Type
Description

Angles.

Example

local ang = math.vector_angles(fw);

world_to_screenīģŋ

Function

Transforms a point in the game world onto the viewport.

Arguments

Name
Type
Description

xyz

Point in the world.

round

bool

Whether should round the output. Defaults to true.

Returns

Type
Description

Point on the viewport.

Example

local point = math.world_to_screen(game_point);

clampīģŋ

Function

Clamps a value between min and max.

Arguments

Name
Type
Description

n

float

Value.

lower

float

Lowest value.

upper

float

Highest value.

Returns

Type
Description

float

Clamped value.

Example

local x = math.clamp(50, 5, 25); -- 25

remap_valīģŋ

Function

Maps the value from one range to another range.

Arguments

Name
Type
Description

val

float

Value.

a

float

Lowest source value.

b

float

Highest source value.

c

float

Lowest destination value.

d

float

Highest destination value.

Returns

Type
Description

float

Mapped value.

Example

local mapped = math.remap_val(0.5, 0, 1, 0, 100); -- 50

remap_val_clampedīģŋ

Function

Maps the value from one range to another range. Additionally, clamps the value based on the source range.

Arguments

Name
Type
Description

val

float

Value.

a

float

Lowest source value.

b

float

Highest source value.

c

float

Lowest destination value.

d

float

Highest destination value.

Returns

Type
Description

float

Mapped value.

Example

local mapped = math.remap_val_clamped(5, 0, 1, 0, 100); -- 100

vec2īģŋ

Function

Example

local vec = math.vec2(5, 5);

vec3īģŋ

Function

Example

local vec = math.vec3(5, 12, 5);
PreviousInstancesNextEvents

Last updated 3 months ago

An alias to .

An alias to .

âš™ī¸
đŸ”ĸ
vector()
draw.vec2()
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vector
vec2