- Home /
Vector1, Vector2, Vector3?
Hello -
I am new to C#. I was wondering if anyone would be so kind as to explain to me exactly what a Vector1, Vector2, and Vector3 array(s) are? I see them often in sample scripts, though I do not clearly understand their meaning. I cannot find a clear definition of what these things are anywhere so far.
I read Microsoft DOCS concerning C# - to no avail. Can anyone please assist me in understanding what Vector1, Vector2, and Vector 3 is? And why/where you would use them? I am asking for an explanation in understanding how to use these things in a practical sense. I thank you for your time - Jah bless.
Vector2 and Vector3 are in the Unity docs, not $$anonymous$$SDN.
Answer by sarthakshah · Sep 18, 2014 at 04:34 AM
Vector2 :- It is representation of 2D vectors and points, used to represent 2D positions, only two axis x&y.
Vector3 :- It is representation of 3D vectors and points, used to represent 3D positions,considering x,y & z axis.
Just wanted to confirm -
If I were making a 2D game I would use Vector2, right? I'm assu$$anonymous$$g yes, but I want to make sure. Thank you, kindly.
No, you'd use Vector3 for things like Transform.position because all objects in Unity are 3D. Technically you could use a Vector2 for that, where it would be implicitly converted to a Vector3 with a Z of 0.0, but that's slightly inefficient. The 2D physics system, however, is "real" 2D and does use Vector2 for many things.
U can make 2d game using Vector3 also, just need to set camera in orthographic mode...
Answer by Landern · Sep 18, 2014 at 03:00 AM
First, there isn't a Vector1 type in unity, technically if you wanted one it would just be a named float type variable.
Vector2 has a bunch of helper methods for basic Vector2, the same goes for Vector3 and Vector4.
Each vector is a struct, a struct is a value type, when you for instance: create a VectorN(where 'N' is 2, 3 or 4) from another VectorN, you are creating a copy of the original VectorN, and it's fields(Vector2 has x and y, Vector3 has x, y and z and Vector4 has x, y, z and w). If you create an object based off a class opposed to a struct, when you instantiate the object based off another object, that object only copies the reference to the original object you're trying to "copy", this reference points to the same values in each object in memory. If you change one, you change the other, however there are caveats to this.
In Unity 3d mode, GameObjects positions are Vector3, or X/Y/Z, where x is typically the horizontal, Y is the vertical and Z is going through he screen. For a Vector2 which could be used for mouse position(X and Y) or in Unity in 2D mode, the X(horizonal) and the Y(vertical) for GameObjects positions makes complete sense right?
Vector4 is a little more specialized(shaders and such, but Vector3 and 2 are also used), though you can use the Vector structs anyway you desire
Both answers helped me understand now. $$anonymous$$any thanks.