Vector2¶
Represents a 2D value with direction and magnitude.
Description¶
The Vector2 data type represents a 2D value with direction and magnitude. Some applications include GUI elements and 2D mouse positions.
Math Operations¶
The following math operations are valid for the Vector2 data type:
| Operation | Description |
Datatype.Vector2 + Datatype.Vector2 |
Produces a Datatype.Vector2 with each component of the second added to the corresponding component of the first. |
Datatype.Vector2 - Datatype.Vector2 |
Produces a Datatype.Vector2 with each component of the second subtracted from the corresponding component of the first. |
Datatype.Vector2 * Datatype.Vector2 |
Produces a Datatype.Vector2 with each component of the second multiplied by the corresponding component of the first. |
Datatype.Vector2 / Datatype.Vector2 |
Produces a Datatype.Vector2 with each component of the first divided by the corresponding component of the second. |
Datatype.Vector2 * number |
Produces a Datatype.Vector2 with each component multiplied by the number. |
Datatype.Vector2 / number |
Produces a Datatype.Vector2 with each component divided by the number. |
Constructors¶
new Supported Returns a Vector2 from the given x and y components.
Returns a Vector2 from the given x and y components. Both
parameters default to 0 if not provided.
Constants¶
zero Not yet A Vector2 with a magnitude of zero.
one Not yet A Vector2 with a value of 1 on every axis.
xAxis Not yet A Vector2 with a value of 1 on the X axis.
yAxis Not yet A Vector2 with a value of 1 on the Y axis.
Properties¶
X Supported The x-coordinate of the Vector2.
The x-coordinate of the Vector2.
The x-coordinate of the Vector2, corresponding to the first argument passed to Vector2.new(). This property is read-only.
Y Supported The y-coordinate of the Vector2.
The y-coordinate of the Vector2.
The y-coordinate of the Vector2, corresponding to the second argument passed to Vector2.new(). This property is read-only.
Magnitude Supported The length of the Vector2.
Unit Supported A normalized copy of the Vector2.
Methods¶
Cross Not yet Returns the cross product of the two vectors.
Returns the cross product of the two vectors.
Returns the 2D cross product of this vector with other, computed as
self.X * other.Y - self.Y * other.X. Unlike Vector3.Cross()
which returns a vector, the 2D cross product returns a scalar representing
the signed magnitude of the perpendicular (Z) component. The result is
positive when other is counter-clockwise from self, negative when
clockwise, and zero when the vectors are parallel.
Abs Not yet Returns a new vector from the absolute values of the original's components.
Ceil Not yet Returns a new vector from the ceiling of the original's components.
Floor Not yet Returns a new vector from the floor of the original's components.
Sign Not yet Returns a new vector from the sign (-1, 0, or 1) of the original's components.
Angle Not yet Returns the angle in radians between the two vectors.
Returns the angle in radians between the two vectors. Specify true for
the optional isSigned boolean if you want a signed angle. By default,
the method returns the absolute value. Signed angles are a negative when
going clockwise. Values are in the range [0, pi] for absolute angles and
[-pi, pi] for signed angles.
Dot Not yet Returns a scalar dot product of the two vectors.
Returns a scalar dot product of the two vectors.
Returns the scalar dot product of this vector and v, computed as
self.X * v.X + self.Y * v.Y. The result equals the product of the two
magnitudes multiplied by the cosine of the angle between them. A positive
value means the vectors point in roughly the same direction; zero means
they are perpendicular; negative means they point in roughly opposite
directions.
Lerp Supported Returns a Vector2 linearly interpolated between this Vector2 and the given goal by the given alpha.
Returns a Vector2 linearly interpolated between this
Vector2 and the given goal v by the fraction alpha, using
the formula self + (v - self) * alpha. An alpha of 0 returns self,
an alpha of 1 returns v, and values between 0 and 1 return a point in
between. Note that alpha is not clamped to [0, 1] — values outside
that range extrapolate beyond the two endpoints.
Max Not yet Returns a Vector2 with each component as the highest among the respective components of the provided Vector2 objects.
Min Not yet Returns a Vector2 with each component as the lowest among the respective components of the provided Vector2 objects.
FuzzyEq Not yet Returns true if the X and Y components of the other Vector2 are within epsilon units of each corresponding component of…
Returns true if the X and Y components of the other Vector2
are within epsilon units of each corresponding component of this
Vector2. The comparison is per-component: both
math.abs(self.X - other.X) and math.abs(self.Y - other.Y) must be less
than or equal to epsilon. The optional epsilon parameter defaults to
1e-5 (0.00001) and must be a positive value no greater than 0.1.
Math operations¶
+ Check Produces a Vector2 with each component of the second added to the corresponding component of the first.
Produces a Vector2 with each component of the second added to the corresponding component of the first.
- Check Produces a Vector2 with each component of the second subtracted from the corresponding component of the first.
Produces a Vector2 with each component of the second subtracted from the corresponding component of the first.
* Check Produces a Vector2 with each component of the second multiplied by the corresponding component of the first.
Produces a Vector2 with each component of the second multiplied by the corresponding component of the first (component-wise multiplication, not a dot or cross product).
/ Check Produces a Vector2 with each component of the first divided by the corresponding component of the second.
Produces a Vector2 with each component of the first divided by the corresponding component of the second (component-wise division).
* Check Produces a Vector2 with each component multiplied by the number.
/ Check Produces a Vector2 with each component divided by the number.
Nova binding inventory¶
| Library | Members |
|---|---|
new |
X, Y, lerp, magnitude, unit, x, y |
Roblox reference: Vector2