Skip to content

Vector4

Client-side
Server-side
Shared

Element category: Vector

Represents a 4D Vector.

OOP-Only Methods and Variables

create

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

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

Calculates the dot (scalar) product of two vectors.

float Vector4:dot ( Vector4 vector )
  • vector: Vector4 – Vector to calculate the dot product with.
getX

Returns the X component of the vector.

float Vector4:getX ( )
Variable: .x
setX

Sets the X component of the vector.

nil Vector4:setX ( float x )
  • x: float – The new X value.
Variable: .x
getY

Returns the Y component of the vector.

float Vector4:getY ( )
Variable: .y
setY

Sets the Y component of the vector.

nil Vector4:setY ( float y )
  • y: float – The new Y value.
Variable: .y
getZ

Returns the Z component of the vector.

float Vector4:getZ ( )
Variable: .z
setZ

Sets the Z component of the vector.

nil Vector4:setZ ( float z )
  • z: float – The new Z value.
Variable: .z
getW

Returns the W component of the vector.

float Vector4:getW ( )
Variable: .w
setW

Sets the W component of the vector.

nil Vector4:setW ( float w )
  • w: float – The new W value.
Variable: .w
normalize

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

bool Vector4:normalize ( )
getNormalized

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

Vector4 Vector4:getNormalized ( )
Variable: .normalized
getLength

Returns the length (magnitude) of the vector.

float Vector4:getLength ( )
Variable: .length
getSquaredLength

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

float Vector4:getSquaredLength ( )
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