distance between 2 vectors

hi guys,, i have a target its pivoy position is(6.0,0.0,0.0) and its center(bull eye) is at (0.0,0.8,0.0),, now i want to calculate the distance between these two through script(javascript),,i know distance formula,,but dnt knw how to solve it in script,,please help

You want to get the distance between the two Vectors?

Then Vector3.Distance is for you:

Clicky, clicky!!

Or Vector2.Distance:

Hit me!

OrangeLightning is right.

Vector3.Distance takes two vectors(a and b) and calculate the distance between them.

var a : Vector3;
var b : Vector3;

var dist = Vector3.Distance(a,b);

is the same as:

var distVec = a - b;
var dist = distVec.magnitude.

magnitude calculates the length of a vector and it's the same as:

var dist = Mathf.Sqrt(distVec.sqrMagnitude);

sqrMagnitude is the squared distance and is the same as:

var sqrDist = distVec.x*distVec.x + distVec.y*distVec.y + distVec.z*distVec.z;

To calculate it without any of the helper functions would be a pain, but fortunately we have them ;) so use them.

Hi you can also find this using simple math. You need to draw a triangle that connects the 2 vectors. You use the Pythagorean Theory to determine the length between the two points

so the formula is

Distance = √(x2-x1)²+(y2-y1)²+(z2-z1)²

Alternatively if you want to be inaccurate but faster you can take the absolute values of each float value and add them all together and divide by 2, like so

|x1|+|y1|+|z1|+|x2|+|y2|+|z2|=d/2

Hope that helps