- Home /
Shortest distance from player to ball direction

I have a moving ball that I want to be intercepted by a player. I need to calculate the distance from the player to the ball direction, as indicated in the picture above. Please help.
Thanks!
Read my answer here, it should help you:
http://answers.unity3d.com/questions/553516/future-position-vector.html
Hi tbkn,
I tried to implement ur methods, but for some reason it does not work for this. What I need now is the find the distance between the player and the ball direction, the perpendicular distance.
Answer by Tomer-Barkan · Nov 04, 2013 at 07:32 AM
Ok, so now that I better understand the problem:
You'd want to calculate the distance between the point and the Ray, as I just answered in your other question here.
In this case, the variables you'd use are as follows:
float distance = Vector3.Cross(ball.rigidbody.velocity.normalized, player.transform.position - ball.transform.position).magnitude;
Edit: Forgot to normalize the velocity.
And if you want to find the actual position where the intersection takes place:
Vector3 meetingPlace = ball.transform.position + ball.rigidbody.velocity.normalized * Vector3.Dot(ball.rigidbody.velocity.normalized, player.transform.position - ball.transform.position
Answer by Sericet1 · Nov 04, 2013 at 03:29 AM
Do you know the coordinates of the intersection point? Do you have the velocity of the ball? You could use basic physics to determine how long it will take the ball to reach the 90 degree point. Use that time to determine how fast the player must go in order to reach that point at the same time.
I have the velocity of the ball and the player. But I do not know the point.
Your answer
Follow this Question
Related Questions
Clarification on how RangeAttribute works 1 Answer
A problem with intersection detection 1 Answer
What's a more efficient way to sort an array into multiple groups? 1 Answer
Programmatically specifying a random point in an arc in front of the player 1 Answer
Finding the axis of a curving pipe 0 Answers