Garry's Mod Wiki

Revision Difference

Global.Angle#560903

<function name="Angle" parent="Global" type="libraryfunc"> <description>Creates an <page>Angle</page> object.⤶ <warning>This function is relatively expensive when used in often running hooks or in operations requiring very frequent calls (like loops for example) due to object creation and garbage collection. It is better to store the angle in a variable or to use the [default angle](https://wiki.facepunch.com/gmod/Global_Variables#misc) available. See <page>Angle:Add</page>.</warning>⤶ <description>⤶ Creates an <page>Angle</page> object, representing a [Euler Angle](https://en.wikipedia.org/wiki/Euler_angles) made up of pitch, yaw, and roll components. ⤶ <warning>⤶ This function is relatively expensive, in terms of performance, in situations where it is being called multiple times every frame (Like a loop, for example.) This is due to the overhead associated with object creation and garbage collection.⤶ Where possible, it is generally better to store an <page>Angle</page> in a variable and re-use that variable rather than re-creating it repeatedly.⤶ In cases where an empty <page>Angle</page> is needed, the global variable `angle_zero` is the preferred solution instead of `Angle( 0, 0, 0 )`.⤶ </warning>⤶ </description> <realm>Shared and Menu</realm> <args> <arg name="pitch" type="number" default="0">The pitch value of the angle, in degrees.⤶ ⤶ ⤶ If this is an <page>Angle</page>, this function will return a copy of the given angle. ⤶ ⤶ If this is a <page>string</page>, this function will try to parse the string as a angle. If it fails, it returns a 0 angle. (See examples)</arg>⤶ <arg name="yaw" type="number" default="0">The yaw value of the angle, in degrees.</arg>⤶ <arg name="roll" type="number" default="0">The roll value of the angle, in degrees.</arg>⤶ <arg name="Overloaded Argument" type="">⤶ This is an [Overloaded Function](https://en.wikipedia.org/wiki/Function_overloading) with these available first arguments: ⤶ ⤶ <page>Number</page> **pitch** = 0 The pitch value of the angle, in degrees. Use this with the second and third arguments.⤶ ⤶ <page>Angle</page> **angle** Creates a new <page>Angle</page> that is a copy of the <page>Angle</page> passed in.⤶ ⤶ <page>String</page> **angleString** ⤶ Attempts to parse the input <page>String</page> from the <page>Global.Print</page> format of an <page>Angle</page>. ⤶ Returns an <page>Angle</page> with its pitch, yaw, and roll set to `0` if the <page>String</page> cannot be parsed.⤶ </arg>⤶ ⤶ <arg name="yaw" type="number" default="0">⤶ The yaw value of the angle, in degrees. ⤶ **Note:** Only valid if the first argument is a <page>Number</page>.⤶ </arg>⤶ ⤶ <arg name="roll" type="number" default="0">⤶ The roll value of the angle, in degrees. ⤶ **Note:** Only valid if the first argument is a <page>Number</page>.⤶ </arg>⤶ </args> <rets> <ret name="" type="Angle">Created angle</ret>⤶ <ret name="" type="Angle">The newly created <page>Angle</page></ret>⤶ </rets> </function> <example> <description>Creates an angle and prints the value to the console.</description> <code> print( Angle( 1, 2, 3 ) ) print( Angle( "4 5 6" ) ) local test = Angle( 7, 8, 9 ) print( Angle( test ) ) print( Angle( "4 5 test" ) ) print( Angle() ) </code> <output> ⤶ ```⤶ ```⤶ 1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 0.00 0.00 0.00 0.00 0.00 0.00 ``` </output> </output> </example>