2D Unity, tracking and distance.

Hey I’m still new to Unity and I’m trying to figure out how I can track two points on a 2D orthographic plane. I also want to calculate distances between the two points for creating scaling variables. The idea is to control growth of a plant and I was thinking of using points to denote sections of each root, branch, and trunk to control the scale and rotation of images pasted over the location of two points.

Thanks for your help!

Dominatro

Here is a quick script that does nothing but provide the distance between two transforms on the XY plane.

How to actually move the Transforms around or display images is up to you!

using UnityEditor;

public class TwoTransform2dDistance : MonoBehaviour
{
  [SerializeField] Transform mPointA;
  [SerializeField] Transform mPointB;

  // Returns the distance between Point A and Point B
  public float Distance {
    get {
      // Here is the key line of code!!!
      return Vector2.Distance(mPointA.position, mPointB.position);
    }
  }
}

Great thanks a lot! I ended up doing the difference with empty game objects using the same method.