Vector Question : Why does the targetPosition minus currentposition = direction

I need some help! Vectors calculations confuse me.

I’ve watched loads of the tutorials on vectors, but I’m still confused by some aspects about them.

Can someone explain (hopefully using laymans terms) why targetVectorPosition - currentPosition = directionVector?

If I could get my head around these vector things It would really help.

some sort of diagram that would be so helpful too!

This is really not a Unity question - it’s a basic maths question. But I’ll try to help you out.

A Vector is a bunch of numbers. A Vector3, which is the most common sort you’ll be using in Unity, is 3 numbers, specifically. When used to describe a position, those numbers represent the distance from an origin in 3 dimensions: x, y, and z.

But if Vector3s confuse you, let’s start with a one-dimensional example instead: a line along the x-axis. So we can describe any position on a line with a single number, representing it’s distance from the origin. Let’s say I’m at position A (x=10), you’re at position B (x=6). How do I work out how to get from A to B?

Well, I need to take away 4, right? So it’s B - A, which is 6 - 10 = -4. It’s just the difference between them.

Now let’s do it in two dimensions. So A and B are now Vector2s. Say that A is (3,10) and B is (8,5). How do you get from A to B now?

So you need to add 5 to the x component of the vector, and take off 5 from the second component of the vector, right? To get from A to B is now (5, -5). Again, you work this out as B - A: (8,5) - (3,10) = (5,-5).

You can follow this approach for vectors of any higher orders as well. To work out how to get from A to B, you just do B - A for each of the components of the vector.

Try Vectors and spaces | Linear algebra | Math | Khan Academy if you’re still confused.

.

a-b is the direction of a from b so the direction of target from position is target-position.