I am making an air hockey game on Android with Box2D and libgdx. For the manual control, I just use the MouseJoint and it works perfectly. However, for the AI control, there is a problem:

I've made a method predicting the position of the puck in the near future (for example in the next 30 frames). Then I tried to move the paddle towards that predicted position such as: after exactly 30 frames, my paddle will arrive in time at a specified point near that position to hit the puck with a specified velocity.

But the problem is, if using MouseJoint, I can't specify the exact interval 30 frames. The paddle will arrive at the specified position, but it maybe sooner than 30 frames, or later than 30 frames. And I can't control the velocity when it arrive at that point either.

What I need here is a way to control my paddle to arrive at a specified point, with a specified velocity in a specified interval. Or is there any other way to control this AI paddle?


1 Answer 1


You have the time (30fps = 0.5seconds) You have the distance (DesiredPosition - Position).Length()

You can calculate your required speed now:

Speed = Distance / Time;

Then just set this speed as your physic's objects velocity, and in theory it should reach the destination. This does not account for drag, friction, etc..


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .