I've seen things about something called "vector3". Typically I see them in scripts that involve teleporting someone or something. Now, I'm studying how to create GUIs and I see a property called "vector2".
I know from physics that a vector is something with direction and magnitude. Does that have to do with anything?
Can someone explain the difference?
Vector2:
A Vector2 has two values - an X ordinate, and a Y ordinate. They're kind of like those coordinates you use in school on graphs. I'm sure you've seen something like
(1, 5)
somewhere before. This means that on a graph you go to the right 1, and then up 5. That's because a coordinate uses an X and a Y value. It looks like this
(x, y)
That's really all there is to it. Usually, the use of Vector2s are in doing simple calculations that UDim2s do not have built in. When people talk about the values inside a Vector2,
X is horizontal, or width Y is vertical, or height
Vector3:
A Vector3 is a userdata that holds three values inside it. This doesn't have to be a 3D position, it could be a size as well.
The three values are an X coordinate, a Y coordinate, and a Z coordinate. When combined, these coordinates can represent a 3D point in space. They're kind of like those coordinates you use in school on graphs. I'm sure you've seen something like (1, 5) somewhere before. This means that on a graph you go to the right 1, and then up 5. That's because a coordinate uses an X and a Y value. It looks like (x, y), sometimes written as x y . This is a 2D vector, or in Roblox, a Vector2. We need a 3D vector, or Vector3. So we add another value, a Z value. This gives us (x, y, z), which can also be written as x y z That's really all there is to it. These numbers can be used for the Position of things, the Size of things, or anything else that needs 3 numbers to work. When people talk about the values inside a Vector3,
X is sideways component, or width. Y is the vertical component, or height. Z is the forward component, or depth.
If this helped click the Accept Answer button.
And i see you're on Scripting helpers Aka, cool!
I'm not 100% sure, but I do know a thing or two. Vector3 is used for sizes, for instance when you see something like this:
Head.Mesh.Scale = Vector3.new(1.5, 1.5, 1.5)
Vector2, and I'm not 100% sure, but I believe that Vector2 is used to certify Gui Positioning. I may be wrong, but that is my guess.
Vector2 and Vector3 are both data types which store vectors.
A vector can only describe a point so much; in its coordinate definition, by specifying a number of measures along different axis.
Vector2s can describe any point in two dimensional space (e.g., something flat, like your screen) (x and y), while Vector3s can describe any point in three dimensional space (x, y, and z) like the world (e.g., directions, sizes, positions).
Vector2 are essentially just Vector3s with a z
component of 0 (although Vector2s lack a z
component since they are only have two dimensions - x
and y
.)
They use the same properties, methods, and math, except for the mentioned lack of z
.