[Still unsolved] Is there some way to cast lines and get the point where they intersect?

So I need the distance between two points.

However, this is harder when the objects are rotated, since the point I need to get is no longer the x and y coordinates of the others (1, 6).

Hope someone answers. Writing in paint was really hard…

I recommend using transform.InverseTransformPoint to calculate the local position of the collision. You should only have to look at the x or z value then (as the origin would be 0,0,0)

The distance between two “points” of course requires you to use all coordinates. Just looking at the x value (no matter if it’s local or world space) of course doesn’t work in every case.

From your code it’s not clear what you actually need. There could be more than 2 collision points and it’s not clear which ones you actually want. If you want to find the two points which are the farthest apart it becomes a bit more complicated. You would need to check each collision point against every other to find the greatest distance.

Basically something like that:

int count = coll.contacts.Length;
Vector3 point0;
Vector3 point1;
float distSqr = 0;
for ( int i = 0; i < count - 1; i++)
    Vector3 p0 = coll.contacts*.point;*

for (int n = i+1; n < count; n++)
Vector3 p1 = coll.contacts*.point;*
float d = (p0-p1).sqrMagnitude;
if (d > distSqr)
point0 = p0;
point1 = p1;
distSqr = d;
float distance = Mathf.Sqrt(distSqr);
Here “point0” and “point1” will contain the two points which are farthest apart from each other and “distance” will contain the distance between those two points. You get the same by using:
float distance = Vector3.Distance(point0, point1);
at the end