Vector/Vector3

From Multi Theft Auto: Wiki
Revision as of 21:35, 2 February 2015 by Qaisjp (talk | contribs) (Restructure)
Jump to navigation Jump to search

The vector3 class represents a three-dimensional vector.

Methods

create

This is default constructor for the Vector3 class and returns a Vector3 object.

Syntax

vector3 Vector3 ( float x = 0, float y = 0, float z = 0 )
  • x, y and z: coordinates for the vector. If not specified, they default to 0.
  • Instead of these three coordinates, a single Vector3 object may be inserted to clone it.

Example

This example sorts all players in a nice line on the center of the map.

Click to collapse [-]
Shared
local players = getElementsByType("player")
local newPlayerPosition = Vector3(-#players - 1, 0, 10) -- Initialize the position vector for the first player in the list
for _, player in ipairs(players) do
    -- Move each player 1 unit forward in X from the previous one
    newPlayerPosition.x = newPlayerPosition.x + 1
    setElementPosition(player, newPlayerPosition)
end

cross

dot

normalize

getX and setX

getY and setY

getZ and setZ

getNormalized

getSquaredLength

getLength