Vector3
Summary
A position or offset in 3D space. See https://docs.unity3d.com/ScriptReference/Vector3.html for more detail on many of these methods or properties
Class Properties
back
A vector of -1 in the z axis
down
A vector of -1 in the y axis
forward
A vector of 1 in the z axis
left
A vector of -1 in the x axis
negativeInfinity
A vector of -infinity in all axes
one
A vector of 1 in all axes
positiveInfinity
A vector of infinity in all axes
right
A vector of 1 in the x axis
up
A vector of 1 in the y axis
zero
A vector of 0 in all axes
Instance Properties
this[index]
number Read/Write
The component at the specified index
x
number Read/Write
The x coordinate
y
number Read/Write
The y coordinate
z
number Read/Write
The z coordinate
magnitude
number Read/Write
Returns the length of this vector
sqrMagnitude
number Read/Write
Returns the squared length of this vector
normalized
Returns a vector with the same direction but with a length of 1
Class Methods
Vector3:New(x, y, z)
Creates a new vector based on x, y and z position
Returns: Vector3
Parameters:
x
number
The x coordinate
y
number
The y coordinate
z
number
The z coordinate
Example
Vector3:Cross(a, b)
Returns the cross product of two vectors
Returns: Vector3
Parameters:
a
The first vector
b
The second vector
Example
Vector3:Lerp(a, b, t)
Linearly interpolates between two points
Returns: Vector3 (A point somewhere between a and b based on the value of t)
Parameters:
a
The first point
b
The second point
t
number
The value between 0 and 1 that controls how far between a and b the new point is
Example
Vector3:LerpUnclamped(a, b, t)
Linearly interpolates (or extrapolates) between two points
Returns: Vector3 (A point somewhere between a and b based on the value of t)
Parameters:
a
The first point
b
The second point
t
number
The value that controls how far between (or beyond) a and b the new point is
Example
Vector3:Max(a, b)
Creates a vector made from the largest components of the inputs
Returns: Vector3
Parameters:
a
The first vector
b
The second vector
Example
Vector3:Min(a, b)
Creates a vector made from the smallest components of the inputs
Returns: Vector3
Parameters:
a
The first vector
b
The second vector
Example
Vector3:Slerp(a, b, t)
Spherically interpolates between two vectors
Returns: Vector3 (A point somewhere between a and b based on the value of t)
Parameters:
a
The first point
b
The second point
t
number
The value that controls how far between (or beyond) a and b the new point is
Example
Vector3:SlerpUnclamped(a, b, t)
Spherically interpolates (or extrapolates) between two vectors
Returns: Vector3 (A point somewhere between a and b based on the value of t)
Parameters:
a
The first point
b
The second point
t
number
The value that controls how far between (or beyond) a and b the new point is
Example
Instance Methods
vector3:Angle(other)
The unsigned angle in degrees between this vector and another
Returns: number
Parameters:
other
The other vector
Example
vector3:ClampMagnitude(maxLength)
Returns a vector with the same direction but with it's length clamped to a maximum
Returns: Vector3
Parameters:
maxLength
number
The maximum length of the returned vector
Example
vector3:Distance(other)
Returns the distance between two points
Returns: number
Parameters:
other
The other vector
Example
vector3:MoveTowards(target, maxDistanceDelta)
Moves a point towards a target point
Returns: Vector3
Parameters:
target
The target point
maxDistanceDelta
number
The maximum distance to move towards the target point
Example
vector3:Project(other)
Projects this vector onto another
Returns: Vector3
Parameters:
other
The other vector
Example
vector3:ProjectOnPlane(planeNormal)
Projects this vector onto a plane defined by a normal orthogonal to the plane
Returns: Vector3
Parameters:
planeNormal
The normal vector of the plane
Example
vector3:Reflect(normal)
Reflects a vector off the vector defined by a normal
Returns: Vector3
Parameters:
normal
The normal vector
Example
vector3:RotateTowards(target, maxRadiansDelta, maxMagnitudeDelta)
Moves this vector towards another with a maximum change in angle
Returns: Vector3
Parameters:
target
The target vector
maxRadiansDelta
number
The maximum change in angle
maxMagnitudeDelta
number
The maximum allowed change in vector magnitude for this rotation
Example
vector3:ScaleBy(other)
Multiplies two vectors component-wise
Returns: Vector3
Parameters:
other
The other vector
Example
vector3:SignedAngle(other, axis)
Returns the signed angle in degrees between two points and the origin
Returns: number
Parameters:
other
The other vector
axis
The axis around which the vectors are rotated
Example
vector3:Add(other)
Adds two vectors
Returns: Vector3
Parameters:
other
The other vector
Example
vector3:Add(x, y, z)
Adds x, y and z values to this vector
Returns: Vector3
Parameters:
x
number
The x value
y
number
The y value
z
number
The z value
Example
vector3:Subtract(other)
Subtracts a Vector3 from this vector
Returns: Vector3
Parameters:
other
The vector to subtract
Example
vector3:Subtract(x, y, z)
Subtracts x, y and z values from this vector
Returns: Vector3
Parameters:
x
number
The x value
y
number
The y value
z
number
The z value
Example
vector3:Multiply(value)
Multiplies this vector by a scalar value
Returns: Vector3
Parameters:
value
number
The scalar value
Example
vector3:ScaleBy(x, y, z)
Multiplies this vector by x, y and z values component-wise
Returns: Vector3
Parameters:
x
number
The x value
y
number
The y value
z
number
The z value
Example
vector3:Divide(value)
Divides this vector by a scalar value
Returns: Vector3
Parameters:
value
number
The scalar value
Example
vector3:NotEquals(other)
Is this vector not equal to another?
Returns: boolean
Parameters:
other
The other vector
Example
vector3:NotEquals(x, y, z)
Is this vector not equal to these x, y and z values?
Returns: boolean
Parameters:
x
number
The x value
y
number
The y value
z
number
The z value
Example
Last updated