Hello
I am a new scratcher , the ping pong game I found here is "4 pong" which have some tricky kind of equation for reflecting the ball when it hits the paddle ...
I am considering to use the true equations .. like I mean:
1- sin[0] in the deflection equation when the ball hits this side of the paddle
2- sin[1] in th deflection equation when the ball hits that side of the paddle
3- sin[2] in the deflection equation when the ball hits that side of paddle ... and so on .
scratcher333
Offline
If you want something that is simpl(er) and still does its job fairly well, I would use the script for the ball:
When start clicked
forever if touching paddle or if touching edge
rotate direction (whichever) direction - 180 degrees
move 5 steps
And here it is in pictures:
<when green flag clicked>
<forever>
<if><< <touching[ paddle <or> <touching[ edge >>
<turn cw( (( <direction> <-> 180 )) )degrees>
<move( 5 )steps>
I hope I could help!
Offline
That doesn't necessarily do it correctly Shadow, that just makes it move the opposite way, not bounce.
Offline
Magnie wrote:
That doesn't necessarily do it correctly Shadow, that just makes it move the opposite way, not bounce.
It bounces correctly if bouncing head on, but not at an angle. Bouncing is an interesing problem, I think we could use some bouncing blocks.
Last edited by greenflash (2009-09-29 22:36:24)
Offline
[Bounce if touching |sprite/edge|]
Offline
How about not using trig at all?
Have 2 variables xVel and yVel
If the ball bounces on the left or right side multiply xVel by -1
If the ball bounces on the top or bottom side multiply yVel by -1
And make the ball move using xVel and yVel
Scratch lacks some trig functions so that makes things like this more difficult.
Last edited by archmage (2009-09-29 22:41:17)
Offline
I'm looking for this too...
Offline
I just posted something you can use.
Offline
Magnie wrote:
That doesn't necessarily do it correctly Shadow, that just makes it move the opposite way, not bounce.
I know it is not perfect, as I explained in my post. But that is the general method used in Pong programs.
Offline
Shadow, your way is totally incorrect. You can't have it just turn around.
My method however, works.
Offline
Hmm...
[blocks]
<when green flag clicked>
<forever>
<if><touching[ Paddle ]>
<turn cw( 180 )degrees>
<if><( <direction> <>> # )>
<turn cw( 45 )degrees>
<end>
<if>( <direction> <<> # )>
<turn cw( 45 )degrees>
<end>
<end>
[/blocks]
Does that work some what? I just made it up in a flash, Ima go make a reflection project...
Offline
Here it is! http://scratch.mit.edu/projects/Magnie/701486 Press space to change the sprite that the ball bounces off of, different bouncing with different angles!
Offline
archmage wrote:
Shadow, your way is totally incorrect. You can't have it just turn around.
My method however, works.
I made a mistake. Sorry.
After the move () steps you have to have a block like this
turn (pick random ( + ) to ( - ) degrees (typically 20 works best).
Offline
Random choosing won't work properly, just goes in random directions after touching something.
Offline
It does in fact, work reasonably well. And it is not completely random either. Check the sample pong project.
Offline
It is completely random. It turns in a randomly generated direction.
Also, the sample pong project is not coded for accuracy so they did made the code basic n easy .
Last edited by archmage (2009-10-02 09:05:49)
Offline
archmage wrote:
It is completely random. It turns in a randomly generated direction.
Also, the sample pong project is not coded for accuracy so they did made the code basic n easy .
You know you don't have to argue with everything I say. It gets irritating. And considering this is a new user who has no experience (or at least little) experience with things like this, I would go with mine.
Offline
If you don't want me to correct you then don't be wrong.
The OP wanted accuracy and you didn't deliver.
Offline
I would try this:
[blocks]<when green flag clicked>
<forever>
<move( 5 )steps>
<if><touching[ paddle
<set{ olddirection }to( <direction>
<point towards( paddle
<turn cw( (( 180 <+> <{ olddirection }> )) )degrees>
<end>
<end>[/blocks]
Last edited by floppy_gunk (2009-10-03 00:28:19)
Offline
I tried yours , Floppy, but it doesn't work to well. Go check mine out. ^.^ Better but not perfect...
Offline
http://scratch.mit.edu/projects/Locomule/709464
Probably not the best solution but one I came up with just for fun. If you want to do 'true' angle based reflections, here is an idea off the top of my head...
Assuming your paddles are on the left and right sides of the screen and moving only vertically, when ball and paddle collide subtract ball y from paddle y, multiply that by a small amount (this will allow you to fine tune the bounce amount later), inverse that and add it back to the normal 90º angle already figured.
Sounds good anyway The cool thing is instead of like some Pong games I've played where you could only reflect the ball off your paddle at a few angles, this should give you a huge, smooth range of bounce angles. You may have to do something different for the ends of the paddle and maybe make a dead zone (regular reflection) in the middle depending on how much you want to fine tune the paddle angle sweep.
Peace
Offline