• 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 Pauls · Nov 21, 2012 at 05:20 PM · timedistanceanglelocationthrow

Time a ball is thrown in the air?

Hi,
if we know the angle, and the distance, or the force to add to the rigidbody, (no matter if it is a normal addForce or with an acceleration), is it possible to calculate the time the ball will be thrown in the air?

I plan to have a character ready to catch the ball, so i would need to set a meeting point between his position, and the time the ball will be thrown in the air, so that they arrive at the same time at the destination point. Do you have any tips to achieve this?

Thanks

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 Steve Steven · Nov 21, 2012 at 06:00 PM 0
Share

So you want to create an AI which catch the ball. This is a really interesting physics answer, but is too much difficult, as we don't know the PhysX by nVidia of Unity3d. I try to solve this, and if I got, I will post here.

avatar image Steve Steven · Nov 21, 2012 at 06:26 PM 1
Share

I didn't tryed untill now, I suggest you to create a script to follow the ball, because for example when you play volleybal, you start to follow the ball if is in your range, you don't calculate when the ball will hit the ground, but only where and how to get it.

avatar image Pauls · Nov 21, 2012 at 06:30 PM 0
Share

@SteveSteven : edit: sorry i did not see your second message, alright good proposition! i will try [Thanks, yes, even if it is not extremely precise. I thought i could even create "steps" and only throw the ball with few forces, and calculate then the time needed with force1, force2, and force3. But maybe not the best approach ;-) ]

avatar image Steve Steven · Nov 21, 2012 at 06:36 PM 0
Share

I never created something like this, but I think that this will be a good approach! Good luck.

2 Replies

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

Answer by Pauls · Nov 23, 2012 at 12:04 AM

Ok, i got by with something like that, to find a middle point, and check if the receiver needs to go further or just wait for the ball :

     bestY = transformR.position.y;
     if (oldY < bestY) oldY = bestY;
     else if (oldY > bestY && !vectorAlreadyFound){
         vectorAlreadyFound = true;
         vectorMiddlePoint = transformR.position;
         distWithMiddlePoint = (vectorMiddlePoint - startingPoint).magnitude;
         if (character behind this limit)
     }

Then, i don't calculate the time, but as Steve suggested, i can make the receiver follow the ball until it reaches the ground.

Thanks for your answers, it helped me a lot!

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 Steve Steven · Nov 23, 2012 at 02:34 PM 0
Share

It was a pleasure, good luck!

avatar image
1

Answer by Meltdown · Nov 21, 2012 at 06:39 PM

You can get the balls direction vector and use that to set a target point based on the magnitude of the balls velocity.

Of course you'll need to take into account whether the ball is going up into the air, or coming down, based on this you can determine how near the ball is to reaching it's target.

Comment
Add comment · Show 5 · 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 Pauls · Nov 21, 2012 at 09:03 PM 0
Share

@GregQuinn Thanks, so the receiver has the same direction vector as the ball, and then how can we deter$$anonymous$$e the distance of the target point, if the ball is going to come down at 100m away from the starting point, or 200m ? in other words, when to decide if the receiver has to go further and continue running, or at the other hand if he has to stop and wait for the ball?

avatar image Meltdown · Nov 21, 2012 at 09:12 PM 0
Share

Is the receiver and the thrower the same person? If the thrower is the receiver, then yes, he can just follow the XZ position of the ball.

If the receiver is another agent, the receiver needs to move to a target in the direction of the balls movement vector.

You'll need to slow up/speed down the receiver's speed for arriving at the target point based on the balls height and its velocity and based on whether the ball is going up or co$$anonymous$$g down. Obviously if the ball is co$$anonymous$$g down, and the receiver is far away still, he'll need to run very fast to get into place. But if the ball is still on an upward flight path, he will perhaps have more time to arrive and can slow down.

Think of a human catching a ball, as they near position to catch, they will slow down and stabilise, getting ready for the catch, if they are far away from the landing point of the ball, they will be running faster to get there. This is the effect you should try and achieve.

avatar image Pauls · Nov 21, 2012 at 09:51 PM 0
Share

@$$anonymous$$eltdown thanks $$anonymous$$eltdown, yes this is what i did not really understand : how to find the target point, based on the direction vector? The receiver is indeed another agent, for now i have the angle and the distance between the thrower and the second character, but i am not sure how much "force" i should give to the ball to arrive near the receiver, and how to detect the target point, in order to tell the receiver to speed up or slow down?

avatar image Meltdown · Nov 23, 2012 at 06:38 AM 0
Share

You don't adjust the 'force' of the ball to arrive neat the target receiver, the receiver adapts to the ball, not the ball to the receiver. when did you see a ball chance its flight mid air to land in a receiver's hands? :)

avatar image Pauls · Nov 23, 2012 at 03:30 PM 0
Share

@$$anonymous$$eltdown yup, thanks, issue solved ;)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Creating an equation to simulate time based on rate and distance. 0 Answers

Length between GPS-locations 1 Answer

Need to Find Distance Between Mouse Cursor and Object in a 2.5D SideScroller 1 Answer

How to calculate a new position having angle and distance? 1 Answer

Fixed Joint2D Malfunctioning? 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