Вопрос

Trying to understand (did not take many math classes, so I apologize I know I should know this) what it means when I have some code that takes 2 vectors and subtracts one from the other to equal a new vector. I kind of get what a vector in unity is, it's like a point with 3 numbers that represent it's position in the world. But what I am confused about is when I have this for instance

Transform target = GameObject.FindWithTag ("Player").transform;
Vector3 targetDir = target.position - transform.position;

So I obviously know what subtraction means, but what I am trying to understand is what the new targetDir is since you're subtracting 2 points, not numbers. Do you simply just minus the equivalent axis (x-x, y-y, z-z) and that gives you the new vector?

Это было полезно?

Решение

An image speaks more than a thousand words:

enter image description here

Другие советы

Put simply: Yes. Subtraction of vectors is equivalent to a composition of subtraction of their components, or in other words, P2 - P1 = { x2 - x1, y2 - y1, z2 - z1 }.

http://hotmath.com/hotmath_help/topics/adding-and-subtracting-vectors.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top