🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help on Optimization Problem for Tennis Ball Physics + prediction

Started by
41 comments, last by kenBlade 5 years, 3 months ago
Hi, my team and I are stuck at section 3.2 of this PDF attached (link below too). We are implementing realistic ball flight with prediction for our tennis game made in Unity and need help with this optimization problem.
 
In a a nutshell, we are implementing realistic tennis ball flight in our game and require a prediction algorithm so that the player can control where the ball lands precisely via mouse cursor.
 
If this is something you are familiar with and would like to take a shot, please let me know. Any help would be super appreciated!
 
Screenshots:
 
image.png.42c7eb0ec38f7bea4edf913c9780a201.png
image.png.913f85d7f905f5186b7453b2d7ce3a8a.png
 
 

video game tennis ball physics 39.pdf

Advertisement

I have coded something like this in 3D, but I lost the source code. I have no idea about applying optimizations. I would avoid optimizations until you have the rest of the code working successfully.

Getting the ball's path in 3D space also must take into account the Magnus force. There is also a wind force, if you want to get physical. Here force F = ma, where a = F/m.

Getting the server's ball's initial velocity and initial angular velocity, to solve for the region that you've mouse-clicked on, is not simple. The naive method is to serve many balls and find the one that lands closest to the mouse click. What method are you trying now? Are you familiar with the concept of gradient descent? Once you find the landing spot closest to the mouse click, you can use gradient descent to hone the location: https://en.wikipedia.org/wiki/Gradient_descent

Getting the ball's path in 3D space also must take into account the Magnus force. There is also a wind force, if you want to get physical. Here force F = ma, where a = F/m

-not doing wind force as thats too sim heavy for now

 

Getting the server's ball's initial velocity and initial angular velocity, to solve for the region that you've mouse-clicked on, is not simple. The naive method is to serve many balls and find the one that lands closest to the mouse click.

-someone just suggested the same thing to me. thought it was a viable way. how is this naive? (are are developing for PC/mac and not mobile). Could this be a valid workaround until a more efficient solution is devised?

 

What method are you trying now? Are you familiar with the concept of gradient descent? Once you find the landing spot closest to the mouse click, you can use gradient descent to hone the location: https://en.wikipedia.org/wiki/Gradient_descent

-haven't started, still on the drawing board. Are you on discord? would like to discuss with you further. Posting here is good too!

I'm kenBlade#2331

I forgot to mention that you should also take drag into account.

Naive because it's a brute force method. Im sure there's some analytical solution, but I don't know it.

I'm not on discord. I am on GitHub. Can you post the code to GitHub, please? I ask only because all of my source code is in the public domain, so I expect the same from everyone.

Are you working in 3D or 2D?

 

P.S. cowcow was my temporary account.

 

I'm working in 3D. Were you able to find your source code?

I'm happy to post my code to GitHub if I get to view yours. Can you provide the link here. while I get everything uploaded to GitHub?

 

For drag, I'm using Unity which takes care of drag for Rigidbodies. However if it has limitations in reaching my gameplay goals, I'm willing to consider implementing a custom solution. I just don't have the expertise to implement anything custom on my own, hence this forum post ;)

I lost my code years ago, sorry. It's lost for good. :(

Don't worry about sharing your code. :) I wish you the best of luck.

would you be able and willing to recode it? I'd be happy to compensate you hourly or as a lump sum if you have an estimated # of labor hours.

 

Since code sharing isn't mutual at the moment, I prefer to keep my code closed source for now. But if we reach a workable solution together on a pro bono basis, I'm happy to make it open source.

 

In other words, please let me know if either of these options are possible: 1) contract work with closed source code, or 2) open collaboration and open source upon completion.

Let me think about it. I'm leaning toward doing it myself from scratch. I won't worry about things like collision with a net, just to simplify everything -- you can worry about those details later. The code would be in the public domain, so don't worry about compensation. I'll use OpenGL 1.x code, so it's fairly simple to follow (and replace, with your own code, if you like).

Do you already have the code that converts a mouse-click into a location on the court?

Are you using C++?

i could implement that. However right now my problem is I have 2 different test scenes (as-is) but have not integrated both into 1 test scene (ideal).

 

Scene #1: Right now the ball always launches towards an invisible game object. All I would simply need to do is set the object position to mouse position. However this is for my test scene w/o magnus force. Based on this projectile tutorial - https://vilbeyli.github.io/Projectile-Motion-Tutorial-for-Arrows-and-Missiles-in-Unity3D/

 

 

Scene #2: For my scene with magnus force, I don't know how to control the landing point yet since the algorithm is different. X distance is unknown and calculated from everything else. But for a skilled programmer, it shouldnt be hard to merge my code for these two different scenes.

demo 1 - https://www.youtube.com/watch?v=gXmA37uDTUE&list=PLqXAcOsVnsHtyRhTjHveqCe0cjq9lPCRv&index=5&t=5s

demo 2 - https://www.youtube.com/watch?v=dVBn1gRy3co&index=5&list=PLqXAcOsVnsHtyRhTjHveqCe0cjq9lPCRv

 

Based on this PDF - https://www.google.com/url?sa=t&source=web&rct=j&url=http://web-ext.u-aizu.ac.jp/labs/is-se/conference_proceedings/iwait-15/39.pdf&ved=2ahUKEwi-pO2_qPDgAhUe9LwKHfkQD78QFjAOegQIAxAB&usg=AOvVaw0Eb9B9Pj_Ilqs_BdCc3Sy1

 

 

It is potentially a difficult problem if you don't have access to the exact calculations used in the physics. On that basis if you wanted to do it the way you are thinking you might be better doing the ball physics yourself.

However this is for a game, so smoke and mirrors. My first thoughts were, send off the ball towards the destination with a ballpark solution, then refine it by applying forces in flight.

Then I just thought of a far simpler way which may achieve what you want. Find a ball park solution for ball going from player A to destination B. Then find a reverse rough solution going backwards from the destination towards player A. Neither of these has to be exact. Then in flight, simply lerp between the two solutions.

This topic is closed to new replies.

Advertisement