How to calculate the path of an object

Rock on.  

Keep in mind.  You don’t have to make a perfect PONG.  

If you can make the game such that:

  • two players can play,
  • it handles scoring,
  • ball motion is purely handled by box2D collision responses (i.e. bouncing; try to solve this without changing the velocity every time it hits a paddle),

… then you are ready to move on to another game like  breakout or space invaders.

  1. No.  This doesn’t handle a reflected bounce.  At least not directly

  2. Yes. Remember, you are doing this check every frame (or less often if you take my advice from the other forum thread).  So, you’ll be constantly determining where the paddle needs to move to.  i.e. Once the ball gets past the wall bounce, the vx,vy will intersect at a new point on the line.

If you get entirely stuck let me know later today.

I will update the example with a paddle mover so you can see it in action.

However, you said you want to self solve and I think you can.  So, give it a good go and then ping back here with an update on your progress either way.

Ok, thank you!

You asked a question and deleted it, but the answer is (you may have figured this out already, thus the deletion)…

You don’t need the angle.  You need vx,vy.

This is weird.  I keep seeing questions in my e-mail, but when I come here they are gone.  

Hey.  I’m going offline.  So’ll check back and see if you got stuck or succeeded tonight.

-Ed

Unfortunately, I was not able to succeed. I kept getting stuck on the part where it has to calculate the path after the object has bounced off the wall.

if you watch the ai of most existing pong games, they just do something very simple like:

if (ball above paddle) then   -- move up, either at a built-in fixed speed, or as some ratio of the vertical separating distance -- or choosing among those two options based on the \_horizontal\_ separating distance end -- and similarly for below/move down

and it’s often surprisingly effective, even without bounce prediction.  sure it’s not perfect, but that tends to actually aid gameplay, because if the ai never failed then it would be too hard.

having said that, calculating bounces isn’t that hard, if you’re determined to do it like that anyway.  since you guys are talking vectors (and even calculus) the reflection formula is: r=d-2n(d.n), where d is the input vector (path of the ball), n is the surface normal (a unit vector perpendicular to the wall, just <0,1> or <0,-1> for horizontal walls), and r is the resulting reflection of d about n (the NEW path of the ball).

Ok, so how would I implement this formula into code? I really want to do it this way, so I can expand my knowledge on vectors.

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.