I am measuring the distance between two objects with the script below. Anyway, how can I measure the distance only in the x and z axis? Basically, I would like to omit the altitude of objects when measuring the distance between them. Is there any simple way to do this?
var distance: float;
var A : GameObject;
var B : GameObject;
function Update () {
// calculate distance between A and B
distance = Vector3.Distance(A.transform.position, B.transform.position);
}
Thanks for offering to help me menneske! Anyway, I ran to some problems when testing the script. Below is the script like I have it right now. Do you have idea what is causing the problem?
According to Unity: Assets/Scripts/NewBehaviourScript.js(9,8 ): UCE0001: ‘;’ expected. Insert a semicolon at the end.
I inserted the semicolons but then Unity claims: Assets/Scripts/NewBehaviourScript.js(9,1): BCE0034: Expressions in statements must only be executed for their side-effects.
var distance: float;
var A : GameObject;
var B : GameObject;
function Update () {
// calculate distance between A and B
Vector3 p1 = A.transform.position;
Vector3 p2 = B.transform.position;
p1.y = p2.y;
distance = (p1-p2).magnitude;
}