How to calculate a Vector3 point having three given Vector3 points and an angle of 90 degrees?

Hello together!

I’m currently implementing an obstacle avoidance system. I have my main character (1), a small obstacle (2) and the desired destination (3).

Trying to move my character to the desired destination results in detecting the obstacle within its range. Now i want to send the obstacle away to make way for the character.

I am casting two rays (yellow) outside character’s range (blue) with the additional range of the obstacle’s radius.

I would like to start checking valid positions for the obstacle at point 4 - let’s call it position x on the left ray. If this point isn’t valid cause of another kind of obstacle at this place, I will check the same position on the other ray. If this position is false too, I would like to increase the position x to x+1 and check again.

To get a ray point I could easily make use of:

Ray ray;
ray.GetPoint(float distance);

But to start exactly at point 4 I need to get the distance from character’s position to the white arrow on the green line somehow.

So how can I calculate this specific distance or at least the point where the white arrow is pointing to?

If I understand it correctly, you want the point which is the projected point of the obstacle point onto the green line.

Unity has a function for that:

You could also calculate it yourself using the dotproduct.