How to calculate the path of an object

OK, here is how to move the paddle to the intersection point:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/auto_paddle.zip

I will be releasing a number of PONG variants with the next SSK2 release. So, any further examples will have to wait till then.

https://www.youtube.com/watch?v=Vek2S2_UHus&feature=youtu.be

Cheers,

Ed

Some time back when I was writing my page curl plugin, I mentioned somewhere in the thread that kicked it off, “Maybe I’ll write some notes about that.” Well, I tried and got about halfway through writing up an article, and realized “I probably need to explain the math.” At some point I noticed that this needed more treatment, so I started making individual articles. To my surprise, as I did revisions, these auxiliary articles continued to grow, and all along I was trying to keep them consistent with one another.

Well, I’d like to see them through, but it probably will be some time before that happens. In case it’s of any use, here are my WIPs:

Triangles (Start here. Needs some treatment on lines. A few of the middle sections should be rearranged; in particular, similar triangles should go at the end and get more development. Interpolation needs a better treatment.)

Circles (Builds on triangles. Really needs a stronger similar triangles background than the first article gives. Many sections still not fleshed out; meanwhile, some should be removed or cannibalized for other sections.)

Centers (Builds on circles, but more like “practice” with the skills from the first two articles.)

Vectors (Builds on triangles and circles. Needs considerable rework / enhancement.)

Page Curl (Depends quite a bit on circles and slightly on vectors. Only about half done, as it was also going for a little excursion on API and shader design.)

(Err, I grabbed one of Greg Pugh’s articles and used it as a template, thus a lot of the non-article details of the pages should be ignored.  :P)

The vectors article sort of cries for a follow-up matrices article, since all the basics are there. That would lead to conics, or the next step to 3D…

Anyhow, these are incomplete, often poorly organized, probably have errors here and there, could use several revision passes on the prose, contain terrible puns in the section titles, etc. But maybe they’ll be useful to somebody as is.

@StarCrunch Thanks for the articles, I will read through these in detail.

@roaminggamer Thanks for the example!

for horizontal walls, most terms vanish on expansion, leaving just “negate dy”.  that is, if your ball was travelling at <dx,dy>, after reflection it will be travelling at <dx,-dy> (assuming a perfectly elastic collision)

@sdktester15,

Go download SSK2version 2017.008 (from your store page) and then grab the Pong Demos here:

https://github.com/roaminggamer/SSK2_Pong

Release notes and annoucements:

https://www.youtube.com/watch?v=DJvz7mkwE-g

Question: I bought SSK2 Lite on Sellfy, so the only way I can get a new update is through email, but I have not received one yet.

Update notices … sent.  You should have it soon.

Got it! Thanks.

I am getting this error when I try to run the game:

Module 'factories.huds.scoreHUD' not found: no field package.preload['factories.huds.scoreHUD'] no file '/Users/Alex/Library/Application Support/Corona/Simulator/Plugins/factories/huds/scoreHUD.lua' no file '/Users/Alex/Desktop/Corona Games/One-Player Pong/SSK2\_Pong-master/001\_UniPong/factories/huds/scoreHUD.lua' no file '/Applications/CoronaSDK-3022/Corona Simulator.app/Contents/Resources/factories/huds/scoreHUD.lua' no file '/Users/Alex/Library/Application Support/Corona/Simulator/Plugins/factories/huds/scoreHUD.dylib' no file './factories/huds/scoreHUD.dylib' no file '/Applications/CoronaSDK-3022/Corona Simulator.app/Contents/Resources/factories/huds/scoreHUD.dylib' no file '/Users/Alex/Library/Application Support/Corona/Simulator/Plugins/factories.dylib' no file './factories.dylib' no file '/Applications/CoronaSDK-3022/Corona Simulator.app/Contents/Resources/factories.dylib'

I made sure SSK2 Version 2017.008 is in the folder.

Did you follow the directions shown here:

https://github.com/roaminggamer/SSK2_Pong/tree/master/001_UniPong

https://github.com/roaminggamer/SSK2_Pong/tree/master/002_UniPongAuto

https://github.com/roaminggamer/SSK2_Pong/tree/master/003_Pong

Each example has its own README file.

See the ‘before you start’ section of each README.

Thanks, I got it to work.

Hello,

If you know the initial rate/speed and position of an object, you can calculate his total path with calculation.

So make on a paper the speed vX and vY, the position at a time origin and find the equation path on a paper f(x,y), and then solve the equation f(x,y)=y*, where y* is the final destination happens at a time t*.

And use proposition with your width and height screen to have a “grid” to calculate.

Yvan.

Do you know calculus?  

I ask, because I think you’re really talking about intersection testing for two moving bodies.

If you want to calculate the position of a single body moving at a fixed velocity, you don’t need calculus, but if you want to calculate where two independent bodies with their own velocities will intersect, it certainly helps to be a familiar with more advanced mathematics.

In truth, for this scenario, what you really want to calculate is:

  • Vector of the moving ball
  • Where that vector intercepts the line the padde lies on
  • time of that intersection

then, with that information, you can set up your AI/algorithm to:

  • move the paddle there, and if you want
  • add an extra layer and move the paddle at the right (or wrong for a miss) rate

Everything you need for the above is in SSK2.  I’ll see if I can type up a sample later.

PS - The reason you don’t really need calculus here is because there is no acceleration.  If the ball were also acting under force of gravity then you would need to use calculus.  Fortunately, all of the quantities you want can be solved with algebra and a fundamental knowledge of vectors.

A few more questions before I come back with help later.

  • Do you understand the difference between a line and a segment
  • Have you taken any of these: geometry, trigonmetry, or algebra
  • Are you solid on the concept of a vector?  i.e. Can you answer the question, “What information does/can a vector represent?”
    • You don’t need to know everything at that link, but it is a great collection of vector types.
  • Do you know what a unit-vector is?
  • … I may add others later.

@sdktester15,

Hi.  I’m putting together a sample right now to answer the intersect part of this question, but can you tell me:

  1. Have you ever run the Validation code for SSK2?  This is my testbench for verifying features, but I provided it to SSK2 owners because they are also great examples.  There is an intersect example/test in the test suite (test #31 as of today).
  2. Did you examine the SSK2 math2d features/page?

Note: I’m not admonishing you here.  I think you are trying to do this without SSK2, which is awesome because that is how you will best learn the concepts.  However, I worry that I’ve done a bad job of making it easy for folks to find help in my many sources:

The steps are very easy w/ Corona SDK

  1. Calculate the line the paddle lies on.  (Two points representing a line segment will do just fine.)

  2. Get the velocity of the ball.

  3. Calculate two points representing a line segment from that velocity.

  4. Use SSK2 line-line intersect function to determine if there is an intersection and if so where.

I made a demo showing how this works:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/SSK2/forums_help/line_intersect.zip

https://www.youtube.com/watch?v=Zs_xuT4FlaI&feature=youtu.be

In closing, I know I sometime write scary answers (all my answers before the example), and I do this because I want the person asking a question (as well as future readers) to be clear that while the final answer may be elegant, getting to it is not simple and is built on a foundation of knowledge and learning.

I want you guys to be successful in game development (and beyond; this is really a stepping stone to other and bigger things for many of you), but it is crucial that:

  • You never look at a game development problem and think, “That looks simple so it must be easy.”
  • When you discover it is harder than it seems, you not quit.  Instead double down and determine what experience and knowledge gaps you have and fill them.  (This is the bigger and better things part I mentioned above).

Finally, I want all folks who ask questions to truly truly appreciate how hard it is to answer these questions sometimes.  As someone who answers a lot of questions, sometimes I read a question and I feel like my head is going to explode (don’t worry @sdktester15, not not this time).  

Then I have to remind myself.  "This person thinks the answer will be easy to give because they do have gaps in their knowledge and experience, … how can I answer this without coming off as a jerk and without crushing their interest in game development and programming.  (Sometimes I do well, sometimes I fail.)

Cheers,

Ed

I couple of answers to your questions. 

I do not know calculus (it would be amazing to know calculus at the age of 13) , but I do know geometry and algebra, and I am now starting trigonometry.

I understand the difference between a segment and a line. 

I understand the definition of a vector, but not its different types, (I don’t know what is a unit-vector)

Thank you for the example, I will try to work off of what you gave me.

Also, would this example include the possibility of the ball bouncing off of walls?