Garry's Mod Wiki

Vector

  Vector Vector( number x = 0, number y = 0, number z = 0 )
  Vector Vector( Vector vector )
  Vector Vector( string vectorString )

Description

Creates a Vector object.

Creating Vectors 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 vector in a variable or to use the default vectors available. See Vector:Add.

Default Arguments

1 number x = 0
The x component of the vector.
2 number y = 0
The y component of the vector.
3 number z = 0
The z component of the vector.

Argument Overload: Vector Copy

1 Vector vector
Creates a new Vector that is a copy of the given Vector.

Argument Overload: Parse String

1 string vectorString
Attempts to parse the input string from the print format of an Vector.

Returns a Vector with its x, y, and z set to 0 if the string cannot be parsed.

Returns

1 Vector
The created vector object.

Example

Creates a vector and prints the value to the console.

print( Vector( 1, 2, 3 ) ) print( Vector( "4 5 6" ) ) local test = Vector( 7, 8, 9 ) print( Vector( test ) ) print( Vector( "4 5 test" ) ) print( Vector() )
Output:
1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000