Get vector2 coordinate from one object to another
I'm trying to figure out a way to get the coordinate of a direction that is between 2 objects, with 0,0 being the bottom left, and 1,1 being the top right. Is there an easy way to do this? I think this explains it better.
I tried a few things.
With this I was able to get the direction of the blue circle. I couldn't figure out how to normalize it in line with the drawing I have below.
Vector3 lightPoint = PlanetController.Instance.GetLightSource();
Vector3 dir = (transform.position - lightPoint).normalized;
Debug.DrawLine(transform.position, lightPoint + dir * 10, Color.red, Mathf.Infinity);
This also let me get the line, but I couldn't figure out a way to normalize it.
var direction = transform.TransformDirection(lightPoint);
Debug.DrawLine(transform.position, direction, Color.red, Mathf.Infinity);
I'm a bit stumped here. Usually I can just use the camera
Camera.main.ScreenToViewportPoint(PlanetController.Instance.GetLightSource());
but this won't work for objects that are out of the camera view and I don't really want to run a check on every object to see if it's in the camera view.
The following kind of worked, but it only works if the numbers are positive, so the blue ball can only be on the right side.
transform.InverseTransformDirection((Vector3)PlanetController.Instance.GetLightSource() - transform.position).normalized;
I'm not super great at math, so I'm not sure if there's a function that would normalize that. I did try absolute value, but that wasn't it.