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
  • getHitLocation(start, end)
  1. Types

trace

Ray tracing

PrevioususercmdNextdvar

Last updated 2 years ago

A trace can be useful if you want to get the location of blocking things. You will have to use a appropriate start position, often it can be your forward vector. The fraction ranges from 0 to 1 and tells you at how many % the trace hit something. For example if you trace from the origin (0, 0, 0) to (0, 0, 1000) and the fraction is 0.5, that means there is a blocking object at (0, 0, 500)

While the calculation is simple, we're providing a helper method to obtain the hit location .

Properties

  • fraction

  • normal

  • surfaceFlags

  • contents

  • allSolid

  • startSolid

  • walkable

Methods

getHitLocation(start, end)

Returns the hit position of the trace.

Example:

local pointA = Vec3:new(0, 0, 0)
local pointB = Vec3:new(0, 0, 1000)
local trace = engine.trace(pointA, pointB)
local hitPosition = trace.getHitLocation()

if (trace.fraction < 1) then
    print("Hit something at: " .. hitPosition:toString())
end
🧪
here