How to predict where the soccer ball should be intercepted by an AI player after being kicked?
This question has been asked many times before, but most of the answers give solution to the problem where ball (target) is assumed to be moving at a constant velocity.
In my scenario, I'm making a football game. When I kick the ball into a direction by applying some force to the ball's rigidbody, I want a second AI player to find the point in the ball's path where he can intercept the ball. I have attached an image for visualisation.
I know the ball's position, ball's current velocity, AI player's position, AI player's constant speed. How do I find such a point, where AI player can intercept the ball?
I am able to calculate such a point with the current velocity of the ball, but that point is not accurate, and changes as ball's current velocity changes per frame, as the ball can keep slowing down after every frame. This makes the AI player act kind of like a homing missile. Instead, I want the AI player to predict a point and just run to it.
Here's the Code I have till now:
public Vector3 CalculateIntercept()
{
Vector3 pos = Ball.GetInstance().transform.position;
Vector3 dir = Ball.GetInstance().GetVelocity();
dir.y = transform.position.y;
float dist = (pos - transform.position).magnitude;
return pos + (dist / 6.17f) * dir; //6.17 is the AI player's constant speed.
}
There's no drag on the ball, but there is a physics material with friction. I suppose to solve this, I might need to account for acceleration maybe.
Please help me figure this out. Thanks!
Hmm. I also tried simulating physics ahead of time in a separate physics scene, it works; but it seems to give a noticeable lag while physics scene is simulating.
you need to use this formulas to calculate the collision point
https://en.wikipedia.org/wiki/Acceleration#Uniform_acceleration
Your answer
Follow this Question
Related Questions
Play animation based on impact position? 1 Answer
Issue with physic engine 0 Answers
Hit ball with racket 2 Answers
Move 2D ball on any ground 0 Answers