Garry's Mod Wiki

Angle

Angle

List of all possible functions to manipulate angles.

Created by Angle.

Type Name Description
number p or pitch or x or 1 The pitch component of the angle.
number y or yaw or y or 2 The yaw component of the angle.
number r or roll or z or 3 The roll component of the angle.
Metamethod Second Operand Description
__add Angle Returns new Angle with the result of addition.
__div number Returns new Angle with the result of division.
__eq any Compares 2 operands, if they both are Angle, compares each individual component.
Doesn't normalize the angles (360 is not equal to 0).
__index number or string Gets the component of the Angle. Returns a number.
__mul number Returns new Angle with the result of multiplication.
__newindex number or string Sets the component of the Angle. Accepts number and string.
__sub Angle Returns new Angle with the result of subtraction.
__tostring Returns p y r.
__unm Returns new Angle with the result of negation.

Methods

Angle:Add( Angle angle )
Adds the values of the argument angle to the orignal angle. This functions the same as angle1 + angle2 without creating a new angle object, skipping object construction and garbage collection.
Angle:Div( number scalar )
Divides all values of the original angle by a scalar. This functions the same as angle1 / num without creating a new angle object, skipping object construction and garbage collection.
Vector Angle:Forward()
Returns a normal vector facing in the direction that the angle points.
boolean Angle:IsEqualTol( Angle compare, number tolerance )
Returns if the angle is equal to another angle with the given tolerance.
boolean Angle:IsZero()
Returns whether the pitch, yaw and roll are 0 or not.
Angle:Mul( number scalar )
Multiplies a scalar to all the values of the orignal angle. This functions the same as num * angle without creating a new angle object, skipping object construction and garbage collection.
Angle:Normalize()
Normalizes the angles by applying a module with 360 to pitch, yaw and roll.
Angle:Random( number min = -360, number max = 360 )
Randomizes each element of this Angle object.
Vector Angle:Right()
Returns a normal vector facing in the direction that points right relative to the angle's direction.
Angle:RotateAroundAxis( Vector axis, number rotation )
Rotates the angle around the specified axis by the specified degrees.
Angle:Set( Angle originalAngle )
Copies pitch, yaw and roll from the second angle to the first.
Angle:SetUnpacked( number p, number y, number r )
Sets the p, y, and r of the angle.
Angle Angle:SnapTo( string axis, number target )
Snaps the angle to nearest interval of degrees. This will modify the original angle too!
Angle:Sub( Angle angle )
Subtracts the values of the argument angle to the orignal angle. This functions the same as angle1 - angle2 without creating a new angle object, skipping object construction and garbage collection.
table Angle:ToTable()
Returns the angle as a table with three elements.
Returns the pitch, yaw, and roll components of the angle.
Vector Angle:Up()
Returns a normal vector facing in the direction that points up relative to the angle's direction.
Angle:Zero()
Sets pitch, yaw and roll to 0. This function is faster than doing it manually.




Example: Shorthand Angular Index

Indexing by angular single-character component.

local a = Angle( 1, 2, 3 ) print( a.p, a.y, a.r )
Output: 1 2 3


Example: Named Angular Index

Indexing by angular named component.

local a = Angle( 1, 2, 3 ) print( a.pitch, a.yaw, a.roll )
Output: 1 2 3


Example: Vector Index

Indexing by vector single-character component.

local a = Angle( 1, 2, 3 ) print( a.x, a.y, a.z )
Output: 1 2 3


Example: Numeric Index

Indexing by number (most efficient!).

local a = Angle( 1, 2, 3 ) print( a[1], a[2], a[3] )
Output: 1 2 3