## Vector3 propertiesEdit

A Vector3 is an object holding a math vector (which can represent a position, a direction or an offset for instance).

Vector3s contain 3 properties x, y, z.

### Example: **Printing the Y component of a vector in the runtime report**Edit

local position = self.gameObject.transform:GetPosition()print( "Y is: " .. position.y )

Vector3:New

[Vector3] Vector3:New( [number] x, [number] y, [number] z ) [Vector3] Vector3:New( [number] xyz )

Returns a new Vector3.

## Vector3:Length, Vector3:SqrLengthEdit

[number] Vector3:Length() [number] Vector3:SqrLength()

Returns the vector's (actual or squared) magnitude / length.

### Example: **Trimming a vector to a specific length**Edit

local someVector = Vector3:New( 50, 20, 30 ) local maxLength = 10 if someVector:Length() > maxLength then someVector = someVector:Normalized() * maxLength end

## Vector3:NormalizeEdit

Vector3:Normalize()

Normalize the vector

## Vector3:NormalizedEdit

[Vector3] Vector3:Normalized()

Returns a copy of the vector, normalized

## Vector3:AddEdit

Vector3:Add( [Vector3] v )

Adds the specified vector

## Vector3:SubtractEdit

Vector3:Subtract( [Vector3] v )

Subtract the specified vector

## Vector3.LerpEdit

[Vector3] Vector3.Lerp( [Vector3] a, [Vector3] b, [number] amount )

Return the vector resulting from the linear interpolation between vector a and b by the specified amount.

## Vector3.SlerpEdit

```
[Vector3] Vector3.Slerp( [Vector3] a, [Vector3] b, [number] amount )
```

Return the vector resulting from the spherical linear interpolation between vector a and b by the specified amount.

## Vector3.DotEdit

## Vector3.CrossEdit

## Vector3.AngleEdit

[number] Vector3.Angle( [Vector3] a, [Vector3] b )

## Vector3.DistanceEdit

[Number] Vector3.Distance( [Vector3] v1, [Vector3] v2 )

Returns the Distance between v1 and v2

## Vector3.TransformEdit

[Vector3] Vector3.Transform( [Vector3] v, [Quaternion] rotation )

Returns a new version, result of the transformation of the specified vector by the specified rotation

## Vector3 * numberEdit

Returns a new vector whose components are equal to those specified vector multiplied by the specified number

## Vector3 * Vector3Edit

Returns a new vector whose components are equal to each component of the first vector multiplied by each component of the second vector

## Vector3 / Vector3Edit

Returns a new vector whose components are equal to each component of the first vector divided by each component of the second vector

## Vector3 + Vector3Edit

Returns a new vector whose components are equal to each component of the second vector added to those of the first vector

## Vector3 - Vector3Edit

Returns a new vector whose components are equal to each component of the second vector subtracted from those of the first vector

## Vector3:Left, Vector3:Up, Vector3:ForwardEdit

```
[Vector3] Vector3:Left()
[Vector3] Vector3:Up()
[Vector3] Vector3:Forward()
```

Returns a unit vector pointing left (X=-1, Y=0, Z=0), up (X=0, Y=1, Z=0) or forward (X=0, Y=0, Z=-1)

### Example: **Getting a vector pointing forward for a particular game object**Edit

-- Start with the absolute forward directionlocal direction = Vector3:Forward() -- Rotate it to match the object's current orientation direction = Vector3.Transform( direction, self.gameObject.transform:GetOrientation() ) -- relative forward direction

## Vector3:UnitX, Vector3:UnitY, Vector3:UnitZEdit

[Vector3] Vector3:UnitX() [Vector3] Vector3:UnitY() [Vector3] Vector3:UnitZ()

Returns a unit vector pointing on the X, Y or Z axis.