# Struct Vector 3 Distance

Discussion in 'Scripting' started by yellowlabrador, Jan 20, 2006.

Joined:
Oct 20, 2005
Posts:
562
Hello All,

Just need a little clarification.

Per PDF Manual;
Distance
float Distance (Vector3 a, Vector3 b)
Returns the distance between a and b

I am understanding this as the distance between 2 vectors of a object (i.e. GO, colliders etc.)

I am thinking of trying to use it something like this to return the distance of 2 objects.

var theDistance = float Distance (Vector3 Node1, Vector3 Node2);

Thanks,
Ray

2. ### jeremyace

Joined:
Oct 12, 2005
Posts:
1,661
Code (csharp):
1.
2. var theDistance = float Distance (Vector3 Node1, Vector3 Node2);
3.
Needs to change to:
Code (csharp):
1.
2. var theDistance = Vector3.Distance (Node1.position, Node2.position);
3.
Distance is a method of the Vector3 class. You also need to add the .position to the end of your vars to pass the Vector3 of the position to the distance function.

PS:in the docs where is says what type of variable each function is expecting or returning (float Distance (Vector3 a, Vector3 b)) just remember that those types are what the function is expecting or returning and you dont need to declare it with Javascript. So Distance (Vector3 a, Vector3 b) becomes Distance (a,b) as long as a and b are vectors.

Hope that helps,
-Jeremy

Joined:
Oct 20, 2005
Posts:
562
Thanks for the clarification.

Been very busy, just moved to a new home so we'll be playing with Unity again.

Ray

4. ### jeremyace

Joined:
Oct 12, 2005
Posts:
1,661
No problem. Congrats on your new home.

-Jeremy