xhookLua
Game

Vector

Mutable 3D vector in world units; field writes change it, operators and methods return new Vectors.

Methods

Vector

Vector([x [, y [, z]]]) -> Vector
NameTypeDescription
xoptionalnumberDefault 0.
yoptionalnumberDefault 0.
zoptionalnumberDefault 0.

New Vector; missing components are 0.

Non-number, non-nil arguments raise 'number expected'.

vec.x

vec.x -> number

Read and write.

Writing fields other than x, y, z, or non-numbers, raises.

vec.y

vec.y -> number

Read and write.

vec.z

vec.z -> number

Up axis. Read and write.

vec:length

vec:length() -> number

3D length in world units.

vec:length2d

vec:length2d() -> number

Length ignoring Z, like horizontal speed.

vec:dot

vec:dot(other) -> number
NameType
otherVector

Dot product.

vec:distance

vec:distance(other) -> number
NameType
otherVector

3D distance to other, in world units.

vec:normalized

vec:normalized() -> Vector

Unit-length copy; vec is unchanged.

vec:cross

vec:cross(other) -> Vector
NameType
otherVector

Cross product, perpendicular to both.

vec:unpack

vec:unpack() -> number, number, number

Components as three values.

Returns x, y, z

vec:angle_between

vec:angle_between(other) -> number
NameType
otherVector

Angle between two directions, 0 to 180 degrees.

Returns 90 if either vector is zero.

vec:lerp

vec:lerp(to, t) -> Vector
NameTypeDescription
toVector
tnumber0 is vec, 1 is to.

Linear blend: vec + (to - vec) * t.

t is not clamped.

vec:to_angles

vec:to_angles() -> Angle

Direction to view Angle; (target - eye):to_angles() aims at a point.

Returns Roll is always 0

vec:to_screen

vec:to_screen() -> number, number | nil

Projects this world position to the screen.

Returns x, y in pixels, or nil

Single nil when not projectable, like behind the camera.

vec:rotate_yaw

vec:rotate_yaw(degrees) -> Vector
NameTypeDescription
degreesnumberPositive is counter-clockwise from above.

Rotated copy around Z; Z is unchanged.

a + b

Vector + Vector -> Vector

Per-component sum of two Vectors.

Adding a number or Angle raises 'Vector expected'.

a - b

Vector - Vector -> Vector

Per-component difference of two Vectors.

a * b

Vector * number | number * Vector | Vector * Vector -> Vector

Scales by a number; Vector * Vector is per-component, not dot.

a / b

Vector / number -> Vector

Divides each component by a number.

Dividing by 0 gives inf or NaN, no error.

-a

-Vector -> Vector

Negates each component.

a == b

Vector == Vector -> boolean

Exact match on all components, no tolerance.

tostring(vec)

tostring(Vector) -> string

Readable form, also used by print().

Returns Like "Vector(1.0, 2.5, 0.0)"

Vector ยท Lua API ยท xhook