Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TifaOng · Nov 04, 2013 at 03:15 AM · c#math

Shortest distance from player to ball direction

alt text

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!

untitled.png (7.7 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tomer-Barkan · Nov 04, 2013 at 06:53 AM 1
Share

Read my answer here, it should help you:

http://answers.unity3d.com/questions/553516/future-position-vector.html

avatar image TifaOng · Nov 04, 2013 at 06:58 AM 0
Share

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.

avatar image Tomer-Barkan · Nov 04, 2013 at 07:18 AM 1
Share

Ok, I see. Is this 2d?

avatar image TifaOng · Nov 04, 2013 at 07:28 AM 0
Share

Yes, it is.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tomer-Barkan · Nov 04, 2013 at 07:36 AM 0
Share

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
avatar image TifaOng · Nov 04, 2013 at 07:47 AM 0
Share

Thanks tbkn, this works too well!

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TifaOng · Nov 04, 2013 at 03:44 AM 0
Share

I have the velocity of the ball and the player. But I do not know the point.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges