- Home /
I don't understand Vector2 + Vector3
If anyone could help me understand Vectors that would be great as I want to create a 2d platformer with cubes. I'm quite knowledgeable with javascript but when I watch and read tutorials, they use vectors to create a jump script and a good movement script. But I don't understand how vectors work and what they are for, if anyone could leave a detailed explanation or video tutorial on how to use vectors in unity3d that would be great. Thanks.
Answer by POLYGAMe · Apr 01, 2014 at 07:58 PM
A Vector2 stores two floats, one for your X position and one for your Y position in cartesian coordinates. A Vector3 adds the Z position.
Say you wanted to move your character along the x axis. You can simply access the player's x value. You could do this with transform.Translate(5,0,0), where the character will move at a speed of five along the x, or you could access the x variable inside the transform.position Vector3 : transform.position.x += 5. Obviously you'd want to use time.DeltaTime and magic numbers are a no go but basically a Vector2 or a Vector3 are just two or three floats in one easy to manage variable :)
Answer by senc01a · Apr 01, 2014 at 12:39 PM
The concept of vector is broader than Unity in fact it comes from mathematics, usually studied in the early years of high school.
I recommend you to have a look at this video What are Vectors, where you can find information about what they are and some of their operations (addition, product, etc). Please also check this website, Vectors for beginners, which I believe will clarify most of the questions you have at this stage.
2D and 3D vectors are essentially the same, only that 2D vectors only have 2 components (x,y), while 3D vectors have 3 (x,y,z).
In Unity you will be mostly working with 3D vectors as the space is three-dimensional. However, all of the operations apply to both type, and are similar.
Answer by T27M · Apr 01, 2014 at 12:38 PM
Vectors aren't Unity specific.
Your answer
Follow this Question
Related Questions
Why is this boolean value changing? 3 Answers
Comparing vector 3 locations 1 Answer
Teleport to where I click 2D 2 Answers
Lives aren't subtracting, going straight to game over. 2 Answers
Flip over car after tips over? 1 Answer