X/Y/Z distance
Hi Guys n Girls,
I'm making a measurement tool n I had a couple of questions,
has anyone got any ideas on how I could get the X/Y/Z measurements in a similar way?
is their a simple way to connect the 2 "dist" objects with a line render??
Code:
public class Measure : MonoBehaviour {
public GameObject Measure1;
public GameObject Measure2;
public Text label;
public float Distance_;
//public float Distance_x;
//public float Distance_y;
//public float Distance_z;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
Distance_ = Vector3.Distance (Measure1.transform.position, Measure2.transform.position);
label.text = Distance_.ToString ("F2");
}
}
Answer by JVene · Aug 15, 2018 at 10:45 PM
The distance between two "X" coordinates is merely subtraction.
Distance_x = Mathf.Abs( Measure1.transform.position.x - Measure2.transform.position.x );
Repeat for Y and Z, and ignore Abs if you want negative values ( to represent direction, though that's unlikely )
However, you might prefer to change your member storage strategy and try
Distance_v = Measure1.transform.position - Measure2.transform.position;
Where Distance_v is a Vector3, not 3 floats. Then, if you only want positive values, read the values of x, y and z from Distance_v with Mathf.Abs().
While this imposes the potential of negative results, it has one advantage. Distance_v.magnitude replaces your call for distance between two vectors.
Your answer
Follow this Question
Related Questions
How to make a surface glow when its hit by a laser. 0 Answers
LineRender Not Detecting Collison 0 Answers
LineRenderer Raycast Gun Bug 1 Answer
Making Raycast line visible 2 Answers
C# 3D Collider Without Fixed Points or use Mesh Filter Instead? 0 Answers