Skip to content

Vector4

Element category: Vector

Represents a 4D Vector.

OOP-Only Methods and Variables

create

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

create ( ​float|​table|​Vector4 vectorOrX, [ ​float y = 0, ​float z = 0, ​float w = 0 ] )
  • vectorOrX: Vector4, table, or floats indicating vector's coordinates
  • y: If vectorOrX is a float, this is the Y coordinate.
  • z: If vectorOrX is a float, this is the Z coordinate.
  • w: If vectorOrX is a float, this is the W coordinate.
dot

Calculates the dot (scalar) product of two vectors.

float|false dot ( ​Vector4 vectorOne, ​Vector4 vectorTwo )
  • vectorOne: First vector.
  • vectorTwo: Vector to calculate the dot product with.
getX

Returns the X component of the vector.

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

Sets the X component of the vector.

bool setX ( ​Vector4 vector, ​float x )
  • vector: Vector4 to set X coordinate on.
  • x: The new X value.
Variable: .x
getY

Returns the Y component of the vector.

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

Sets the Y component of the vector.

bool setY ( ​Vector4 vector, ​float y )
  • vector: Vector4 to set Y coordinate on.
  • y: The new Y value.
Variable: .y
getZ

Returns the Z component of the vector.

float|false getZ ( ​Vector4 vector )
  • vector: Vector4 to get Z coordinate from.
Variable: .z
setZ

Sets the Z component of the vector.

bool setZ ( ​Vector4 vector, ​float z )
  • vector: Vector4 to set Z coordinate on.
  • z: The new Z value.
Variable: .z
getW

Returns the W component of the vector.

float|false getW ( ​Vector4 vector )
  • vector: Vector4 to get W coordinate from.
Variable: .w
setW

Sets the W component of the vector.

bool setW ( ​Vector4 vector, ​float w )
  • vector: Vector4 to set W coordinate on.
  • w: The new W value.
Variable: .w
normalize

Normalizes the vector to a unit vector (length of 1). Modifies the original vector.

bool normalize ( ​Vector4 vector )
  • vector: Vector4 to normalize.
getNormalized

Returns a normalized version of the vector without modifying the original.

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

Returns the length (magnitude) of the vector.

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

Returns the squared length of the vector (useful to anil square root operations).

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

Code Examples

client

This example adds a command called "/garage", allowing you to get any garage bounding box.

function garageBoundingBox( _, garageID)
if not garageID then
outputChatBox("[Usage] /garage <id>")
return
end
if tonumber(garageID) then
if tonumber(garageID) > 0 and tonumber(garageID) < 50 then
local boundingBox = Vector4(getGarageBoundingBox (garageID))
outputChatBox("West: "..boundingBox.x..", East: " ..boundingBox.y..", South: "..boundingBox.z.." North: "..boundingBox.w)
else
outputChatBox("Garage ID must be between 1 and 49")
end
end
end
addCommandHandler ("garage",garageBoundingBox)

See Also

Vector Elements
Reference