AI for Tennis
I am developing a tennis game.
The problem i am facing is how the opponent should reach for the ball to play better shot?
Mess with the BESTDIE like the rest.
You need to be more specific about what kind of Tetris game you are making and how it works. 3D?, 2D?...
If your game is a simple 2D tennis game then you just need to move the player each frame so that the destination between the player and ball on the x-axis gets minimal. This is the same as in a pong AI.
If your game is a simple 2D tennis game then you just need to move the player each frame so that the destination between the player and ball on the x-axis gets minimal. This is the same as in a pong AI.
This is a 3D tennis game for mobile phones with J2ME as platform. Currently I am having singles match only, but doubles is on cards.
The problem is reaching for a moving ball so that ball won't bounce twice and will not move past over reachable height.
The problem is reaching for a moving ball so that ball won't bounce twice and will not move past over reachable height.
Mess with the BESTDIE like the rest.
This seems more of a physics issue than an AI issue. By using the current position, speed and acceleration of the ball you can calculate when and where it will hit the ground. Assuming there is no friction, ball roation, or other forces affecting the acceleration, this can easily be calculated from the information you have when a player hits the ball:
By doing the calulations component-wise (separate for x and y components), the speed when the ball lands, vy1, is given by the initial speed (vy0) and the height above ground where the racket hit the ball(h):
(1/2)*m*vy0^2 + m*g*h = (1/2)*m*vy1^2 => vy1 = sqrt(vy0^2+2*g*h)
Since the acceleration is constant, the time it took is simply:
s = (vy1-vy0)/g
Now that you know the time from the player hits the ball until it will hit the court, you can also calculate where that is. Simply take the x-direction (or direction in the x-z plane since it's 3D) and the initial speed (multiplying by cos(a) where a is the angle between the vector and the court to get the x component of the speed) and multiply them.
Now you know where and when the ball will hit the court, so you must use similar calculations to have the receiving player be there at that time.
By doing the calulations component-wise (separate for x and y components), the speed when the ball lands, vy1, is given by the initial speed (vy0) and the height above ground where the racket hit the ball(h):
(1/2)*m*vy0^2 + m*g*h = (1/2)*m*vy1^2 => vy1 = sqrt(vy0^2+2*g*h)
Since the acceleration is constant, the time it took is simply:
s = (vy1-vy0)/g
Now that you know the time from the player hits the ball until it will hit the court, you can also calculate where that is. Simply take the x-direction (or direction in the x-z plane since it's 3D) and the initial speed (multiplying by cos(a) where a is the angle between the vector and the court to get the x component of the speed) and multiply them.
Now you know where and when the ball will hit the court, so you must use similar calculations to have the receiving player be there at that time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement