Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Vector2 and Vector3 in Unity?

Tags:

c#

unity3d

Title says it all. I see them used in movement scripts often, if that helps. What is a Vector2 and a Vector3, the Unity docs are a bit hard to follow for new people.

like image 410
falcononpc Avatar asked Dec 23 '22 01:12

falcononpc


2 Answers

Vector's are mathematical models that model both direction and magnitude. A Vector2 is 2D, and a Vector3 3D.

A vector2(1,5) is a direction with the ratio of 1 part x, and 5 parts y. E.G a line 1/6th to the right, and 5/6th's up. a negative would make the line left and down respectively.

Magnitude show's the "strength" of the direction. E.g when using forces and physics, pushing something in a vector2(1,0) is a much weaker push to the right than a vector2(100,0) even though the direction is identical.

That should be a basic theory introduction for you.

like image 176
Prodigle Avatar answered Dec 30 '22 12:12

Prodigle


A Vector is basically a quantity which has a direction: The quantity is referred to as the magnitude of the vector, the direction is referred to as the normalized vector.

Vector is represented using its components: the projection of the vector on each axis is referred to as the components of the vector.

enter image description here

A Vector1 has a 1D direction, like a point on a line, or the value of a steering wheel, or any real number. e.g. (0) or (-1000). The magnitude of a Vector1 equals the absolute value of the x component of the vector or sqrt(x^2).

enter image description here

A Vector2 has a 2D direction, like a xy point in a 2D space, or the position of a joystick stick, or the uv offset of a point on a 2D texture. e.g. (0,0) or (-1, 100). The magnitude of a Vector2 equals sqrt(x^2+y^2).

enter image description here

A Vector3 has a 3D direction, like a xyz point in a 3D space, or a color in RGB format, or a set of three numbers. e.g. (0,0,0) or (-0.1, 3.14, 30). The magnitude of a Vector3 equals sqrt(x^2+y^2+z^2).

enter image description here

A Vector4 has a 4D direction, like a xyzw point in a 4D space, or a color in RGBA format, or a set of four numbers. e.g. (0,0,0,0) or (0.1, 0.2, 0.3, 0.4). The magnitude of a Vector4 equals sqrt(x^2+y^2+z^2+w^2).

enter image description here

like image 24
Bizhan Avatar answered Dec 30 '22 12:12

Bizhan