- Home /
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
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.
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.
@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 ;-) ]
I never created something like this, but I think that this will be a good approach! Good luck.
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!
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.
@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?
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.
@$$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?
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? :)
Your answer
Follow this Question
Related Questions
Creating an equation to simulate time based on rate and distance. 0 Answers
Fixed Joint2D Malfunctioning? 0 Answers
How to calculate direction between 2 objects 2 Answers
Lerp between two angles 1 Answer