0
\$\begingroup\$

I'm really stucked. I couldn't understand what does Vector3 state.

When I look Unity Vector3 documentation it says

Representation of 3D vectors and points.

According to this sentence, a Vector3 can state a point or a vector in space.

But When I go into other documentation about Vector3 it really confused me.

For example When I look Vector3 Constructor documentation it says

Creates a new vector with given x, y, z components.

So that means Vector3 states a vector.

But When I look Debug.DrawLine(Vector3 startpoint, Vector3 endpoint) it says startpoint and lookpoint are points in world space. So according to this, Vector3 is a point not a vector

I can increase the examples.

For example when I go into transform.position documentation it says,

The world space position of the Transform.

So it says Vector3 is a position(that means point. I think you can't state a position with Vector)

But when we try to change a position of gameobject with transform.position we again use Vector3 and that state a vector.Because you can't change position of a gameobject with point. You could use Vector

So, what does a Vector3 state ?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

A Vector3 is a set of 3 float values: x, y, and z. These 3 values can represent whatever you want, but usually are used to represent the three axes of either a position, a vector, or a euler rotation.

You generally should be able to tell what a Vector3 represents from context/variable naming. It's important to make the context clear, to avoid mistakes like this:

Vector3 a = transform.position;
Vector3 b = transform.eulerAngles;
a += transform.forward * speed * Time.deltaTime;
b += rotationSpeed * Time.deltaTime;
//oops, we mixed these up! we should have used better variable names!
transform.position = b;
transform.eulerAngles = a;

Your question is analogous to asking "what does a float represent"? A float simply stores a floating-point value; it isn't inherently a distance or a speed or a time or a weight or any other specific type of unit. The meaning of the value is taken from context, e.g.

float distance = Vector3.Distance(point1, point2);
float time = Time.time;
float speed = 5.5;
\$\endgroup\$
5
  • \$\begingroup\$ Okay I think I got it. Basically What you saying is Vector3 is just three float value. But how come three float value can represent a Vector ? Don't we need at least two point in space to make a Vector ? andhHow can I learn which method represent position, vector or euler rotation ? \$\endgroup\$ Commented Apr 30, 2021 at 0:38
  • \$\begingroup\$ A vector is formally defined as a quantity having direction and magnitude. That definition does not require defining specific start or end points. As I said in the answer, you should be able to determine how the Vector3 is being used from context. \$\endgroup\$ Commented Apr 30, 2021 at 2:01
  • \$\begingroup\$ For example, if we have a point A at (2,2,2) and a point B at (3,3,3), the vector from A to B is (1,1,1). If we have point C at (5,5,5) and point D at (6,6,6) the vector from C to D is also (1,1,1). Those are distance vectors, but the specific start and end points aren't part of the definition. We can also define other quantities, such as velocity, using vectors. \$\endgroup\$ Commented Apr 30, 2021 at 2:13
  • \$\begingroup\$ Thanks for your explanation. Now I understood \$\endgroup\$ Commented Apr 30, 2021 at 3:08
  • \$\begingroup\$ You can think of vector as a point offset away from 0,0,0 then you take that "line" and move it to start from whatever initial point you like. In other words vector is a point away from wherever you choose to begin to "count". \$\endgroup\$ Commented Apr 30, 2021 at 10:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.