Skip to content

Vector2

Element category: Vector

This is a 2D Vector class.

OOP-Only Methods and Variables

create

Default constructor for the Vector2 class. Returns a Vector2 object.

Vector2 create ( ​float|​table|​Vector2 vectorOrX, [ ​float y = 0 ] )
  • vectorOrX: Vector2, table, or float indicating vector's coordinates.
  • y: If vectorOrX is a float, this is the Y coordinate.
normalize

Normalizes the vector.

bool normalize ( ​Vector2 vector )
  • vector: Vector2 to normalize.
getX

Gets the X coordinate of a vector.

float|false getX ( ​Vector2 vector )
  • vector: Vector2 to get X coordinate from.
Variable: .x
setX

Sets the X coordinate of a vector.

bool setX ( ​Vector2 vector, ​float x )
  • vector: Vector2 to set X coordinate on.
  • x: New X coordinate.
Variable: .x
getY

Gets the Y coordinate of a vector.

float|false getY ( ​Vector2 vector )
  • vector: Vector2 to get Y coordinate from.
Variable: .y
setY

Sets the Y coordinate of a vector.

bool setY ( ​Vector2 vector, ​float y )
  • vector: Vector2 to set Y coordinate on.
  • y: New Y coordinate.
Variable: .y
getNormalized

Gets a normalized version of the vector.

Vector2|false getNormalized ( ​Vector2 vector )
  • vector: Vector2 to get normalized version of.
Variable: .normalized
getLength

Gets the length of a vector.

float|false getLength ( ​Vector2 vector )
  • vector: Vector2 to get length from.
Variable: .length
getSquaredLength

Gets the squared length of a vector.

float|false getSquaredLength ( ​Vector2 vector )
  • vector: Vector2 to get squared length from.
Variable: .squaredLength
dot

Gets the dot product of two vectors.

float|false dot ( ​Vector2 vectorOne, ​Vector2 vectorTwo )
  • vectorOne: First vector.
  • vectorTwo: Second vector.

Code Examples

client

Checks if the player is using a low resolution

addEventHandler ( "onClientResourceStart", resourceRoot, function()
local screenSize = Vector2(guiGetScreenSize())
if screenSize.x < 1360 and screenSize.y < 768 then
outputChatBox ("You are running on a low resolution")
end
end)

See Also

Vector Elements
Reference