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
  • Vec3:new(x, y, z)
  • length()
  • distanceTo(otherVec3)
  • distanceTo2D(otherVec3)
  • getXYAngle()
  • normalize360()
  • normalized()
  • scale(scalar)
  • screenPosition()
  • toVec2()
  • toString()
  1. Types

Vec3

A three dimensional vector.

PreviousVec2NextVec4

Last updated 2 years ago

Properties

  • x - double

  • y - double

  • z - double

Methods

Vec3:new(x, y, z)

  • x - What to set x to

  • y - What to set y to

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

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)

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

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

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

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

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)

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

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

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

Returns a string representation of the Vec3

Example:

local vecA = Vec3:new(20, 10, 5)
print("vecA: " .. vecA:toString()) --prints (20, 10, 5)
🧪
constructor
length
distanceTo
distanceTo2D
getXYAngle
normalize360
normalized
scale
screenPosition
toVec2
toString