- Home /
how to intercept a rolling ball/object by a player?
I'm doing a cricket game where the ball has to be fielded. The fielder has to field the ball by intercepting. Lets assume the fielder is running at 3 m/s and the ball is rolling at 5 m/s. The player and the ball are like 20 m apart. How will he intercept the ball at the minimum possible distance?
I am unsure, if I understood the question correctly, but will still take a shot, although a picture or a small video of your problem will help alot to understand it correctly, anyways,
I assume both gameobjects may have a rigidbody and colliders on to it.
So how about using a Vector2.distance function?
So something like calling the below function in an update/Fixed Update/Late Update method
void Stopball() { if(Vector2.Distance(fielder.transform.position, ball.transform.position) < 2 ) {
//set your ball speed (which I assume must be on a decremented basis) to 0
// set its position to player's hand
}
else
{
}
}
Again, what I have answered is very vague, but I just wanted to bring the point up as calculating the distance between the objects might help.
Were you able to find an answer to this? I'm trying to solve a similar problem. @hariprathaap ?
Your answer
![](https://koobas.hobune.stream/wayback/20220612143730im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do i get the Y Velocity of my character? 1 Answer
[Solved] How to shoot an object in front of the player? 1 Answer
Ball stuck horizontally between rackets in pong 0 Answers
Ball is moving with constant velocity but not attaining same distance 0 Answers
Projectile Trajectory Velocity, with predefined Start and End Positions 0 Answers