Link to home
Start Free TrialLog in
Avatar of noxcho
noxchoFlag for Germany

asked on

Script example to catch the position of the ball and move the racquet to that position MQTT

Hi folks, I am trying to solve a task where I need to move the racquet to exact position of automatically moving ball in a simple java written eclipse paho for MQTT broker minitennis game. The publisher delivers the current position of the ball through x80; y88; values of coordinates. See my screen shot. At the moment I cab move the racquet with arrow keys left and right. The goal is to read the values x80; y88; (these values are changing depending on ball position) and move the racquet automatically to catch the ball at the end. User generated image
Avatar of d-glitch
d-glitch
Flag of United States of America image

I can't help with the Java, but I can help with the math.

After the fist two data points, you can see that X is changing by +1 and Y is changing by -1 every time interval.
You have observed the velocity of the ball in the x- and y-directions, and you can predict its motion.

It looks like your paddle moves along Y = 0.

How long before the ball gets to Y = 0 ?   223 steps.
What will its X-position be then?   18 + 223 = 241 !!


ASKER CERTIFIED SOLUTION
Avatar of d-glitch
d-glitch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial