I’ve been trying to figure out how to calculate a point in space using the hypotenuse of a right triangle created with a raycast.

At this point I couldn’t find or think of any solution to this problem.

The blue dots in the image are the values I have at any given momment, and I need to find the ‘E’ value to calculate the distance between B and E.

Can you help me solve this issue?

I came up with the solution for this a couple days ago.

This is a right triangle, and will always be because C is the ground position (y = 0) of A at all times;

Since it’ll always be a right triangle, the distance between A and B is always proportional to the distance between A and E.

Here is how you do it:

Remember: A is a ray origin, and D is a raycast hit point;

```
float AB = Vector3.Distance(A.origin, B.transform.position);
float AC = Vector3.Distance(A.origin, C.transform.position);
float AD = Vector3.Distance(A.origin, D.point);
float proportion = ab/ac; //this gives a float between 0 and 1 to be used as percentage
float AE = AD * proportion;
//Now we use the direction of the ray and AE as the magnitude to find E;
Vector3 E = A.direction * AE;
```

It took me quite a while to understand this, since math is not the strongest of my qualities, but there it is.