xhookLua
Game

Angle

Pitch, yaw, roll in degrees, positive pitch down, yaw 0 along +X; methods and operators return new Angles.

Methods

Angle

Angle([pitch [, yaw [, roll]]]) -> Angle
NameTypeDescription
pitchoptionalnumberDefault 0.
yawoptionalnumberDefault 0.
rolloptionalnumberDefault 0.

New Angle; missing components are 0, nothing is normalized.

ang.pitch

ang.pitch -> number

Positive looks down. Read and write.

Writing unknown fields or non-numbers raises.

ang.p

ang.p -> number

Same as ang.pitch.

ang.x

ang.x -> number

Same as ang.pitch.

ang.yaw

ang.yaw -> number

Left/right turn. Read and write.

ang.y

ang.y -> number

Same as ang.yaw.

ang.roll

ang.roll -> number

Tilt. Read and write.

ang.r

ang.r -> number

Same as ang.roll.

ang.z

ang.z -> number

Same as ang.roll.

ang:forward

ang:forward() -> Vector

Unit look direction.

ang:right

ang:right() -> Vector

Unit right vector.

ang:up

ang:up() -> Vector

Unit up vector.

ang:vectors

ang:vectors() -> Vector, Vector, Vector

Forward, right and up in one call.

ang:normalize

ang:normalize() -> Angle

Copy with each component wrapped to -180 to 180.

Pitch wraps, not clamps; use clamp() for view angles.

ang:clamp

ang:clamp() -> Angle

Valid view angle copy: pitch -89 to 89, yaw wrapped, roll 0.

ang:delta

ang:delta(other) -> Angle
NameTypeDescription
otherAngleAngle to subtract.

Shortest signed difference: yaw 179 vs -179 gives -2.

Returns Wrapped to -180 to 180

ang:length

ang:length() -> number

sqrt(pยฒ + yยฒ), ignoring roll; aim error on a delta.

ang:lerp

ang:lerp(to, t) -> Angle
NameTypeDescription
toAngle
tnumber0 is ang, 1 is to.

Per-component blend the short way round, for aim smoothing.

t is not clamped and the result is not wrapped; call normalize().

ang:unpack

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

Components as three values.

Returns pitch, yaw, roll

ang:clone

ang:clone() -> Angle

Independent copy.

a + b

Angle + Angle -> Angle

Per-component sum of two Angles, not normalized.

a - b

Angle - Angle -> Angle

Per-component difference, unwrapped; delta() gives the shortest.

a * b

Angle * number | number * Angle -> Angle

Scales each component by a number.

Angle * Angle raises 'number expected'.

a / b

Angle / number -> Angle

Divides each component by a number.

Dividing by 0 raises "Angle: division by zero".

-a

-Angle -> Angle

Negates each component.

a == b

Angle == Angle -> boolean

Exact match, no tolerance or wrapping: 180 ~= -180.

tostring(ang)

tostring(Angle) -> string

Readable pitch, yaw, roll; print() shows the same.

Returns Like "Angle(10.0, 90.0, 0.0)"

Angle ยท Lua API ยท xhook