Anvil Scripting Reference
  • Getting started
    • Introduction
  • 🚀Examples
    • Create a speed overlay
    • Creating a Clock with ImGui
    • Calculating Distances Tool
  • ⚙️ User Settings
    • Make use of our settings API
  • 📦Namespaces
    • engine
    • player
    • key
    • mouse
    • memory
    • draw
    • ImGui
  • 🧪Types
    • Vec2
    • Vec3
    • Vec4
    • playerState
    • refDef
    • clientEntity
    • cg
    • usercmd
    • trace
    • dvar
  • 📄Enums
    • CmdButton
    • ImGuiWindowFlags
    • ImGuiStyleVar
    • ImGuiCol
Powered by GitBook
On this page
  • Properties
  • Methods
  • Vec2:new(x, y)
  • length()
  • distanceTo(otherVec2)
  • angleTo(otherVec2)
  • normalized()
  • scale(scalar)
  • toString()
  1. Types

Vec2

A two dimensional vector.

PreviousImGuiNextVec3

Last updated 2 years ago

Properties

  • x - double

  • y - double

Methods

Vec2:new(x, y)

  • x - What to set x to

  • y - What to set y to

Constructs a new Vec2 with the provided x and y.

Example:

local screenPosition = Vec2:new(200, 200)

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)

  • 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)

  • 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()

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)

  • 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()

Returns a string representation of the Vec2

Example:

local vecA = Vec2:new(20, 10)
print("vecA: " .. vecA:toString()) --prints (20, 10)
🧪
constructor
length
distanceTo
angleTo
normalized
scale