Vector3

The Vector3 data type is composed of three numerical components: X, Y, and Z. Vector3 is typically used to represent a position, size, direction, or orientation. Roblox uses Vector3 to represent vectors within a Cartesian coordinate system and orientations in form of Euler angles. Roblox also rarely uses Vector3 as a color ().
In Lua, Vector3 is also known as vector in type function and is treated as a value type unlike other Roblox types.
== Usage ==
Vector3, along with CFrame, is used by properties in the Roblox API to determine the location and orientation of objects.
Unlike CFrame, two Vector3s are used by the Roblox API to represent both positional and rotational data. Vector3 uses Euler angles to determine the orientation, which can encounter gimbal lock. CFrame uses a rotation matrix which avoids this problem.
== Data type ==
=== Constructors ===
Constructor	Description
Vector3.new(number x, number y, number z)	Creates a Vector3 positioned at x, y, z.
Vector3.fromNormalId(Enum.NormalId normalId)or
Vector3.FromNormalId(Enum.NormalId normalId)	Creates a Vector3 that is equivalent to the direction of normalId.
Vector3.fromAxis(Enum.Axis axis)or
Vector3.FromAxis(Enum.Axis axis)	Creates a Vector3 for axis.
===Properties===
Property 	Description
Vector3 Vector3.zero 	A Vector3 whose X, Y, and Z components are 0, 0, 0 respectively. Note that this is a constant and must be accessed through the Vector3 global, not a Vector3 object itself.
Vector3 Vector3.one 	A Vector3 whose X, Y, and Z axes are 1, 1, 1 respectively. Note that this is a constant and must be accessed through the Vector3 global, not a Vector3 object itself.
Vector3 Vector3.xAxis 	A Vector3 whose X, Y, and Z axes are 1, 0, 0 respectively. Note that this is a constant and must be accessed through the Vector3 global, not a Vector3 object itself.
Vector3 Vector3.yAxis 	A Vector3 whose X, Y, and Z axes are 0, 1, 0 respectively. Note that this is a constant and must be accessed through the Vector3 global, not a Vector3 object itself.
Vector3 Vector3.zAxis 	A Vector3 whose X, Y, and Z axes are 0, 0, 1 respectively. Note that this is a constant and must be accessed through the Vector3 global, not a Vector3 object itself.
number Vector3.X 	The X-coordinate of the Vector3.
number Vector3.Y 	The Y-coordinate of the Vector3.
number Vector3.Z 	The Z-coordinate of the Vector3.
number Vector3.Magnitude	The length of the Vector3.
Vector3 Vector3.Unit 	A normalized copy of the Vector3; the vector that has the same direction as the initial Vector3, but with a length of 1.
===Methods===
Method 	Description
Vector3 Vector3:Cross(Vector3 otherVector) 	Returns the cross product of the two vectors.
number Vector3:Angle(Vector3 otherVector, Vector3 axis) 	Returns the angle in radians between the two vectors. If axis is provided, the returned number will be signed (positive or negative).
number Vector3:Dot(Vector3 otherVector) 	Returns the dot product of the two vectors.
boolean Vector3:FuzzyEq(Vector3 otherVector, number epsilon)	Returns whether or not each of the X Y and Z components of the vector are within epsilon units of the other.
Vector3 Vector3:Lerp(Vector3 otherVector, number alpha) 	Linearly interpolates a vector between this Vector3 and otherVector, by the fraction alpha. Note that this can be used to extrapolate as alpha is not constrained between 0 and 1.
Vector3 Vector3:Max(Vector3 otherVector) 	Returns a Vector3 with each component as the highest among the two vectors.
Vector3 Vector3:Min(Vector3 otherVector) 	Returns a Vector3 with each component as the lowest among the two vectors.
===Operators===
Method 	Description
Vector3 Vector3 + Vector3	Returns a Vector3 where each respective axis is added to the other.
Vector3 Vector3 - Vector3	Returns a Vector3 where each respective axis is subtracted from the other.
Vector3 Vector3 * Vector3	Returns a Vector3 where each respective axis is multiplied by the other.
Vector3 Vector3 / Vector3	Returns a Vector3 where each respective axis is divided by the other.
Vector3 Vector3 * number 	Returns a Vector3 where each axis is multiplied by number.
Vector3 Vector3 / number 	Returns a Vector3 where each axis is divided by number.
== Referenced by ==
==References==
Category:Roblox typesCategory:Value types