making the ball bounce back

HumanNature's icon

Hi everyone,
I'm working on a patch in jitter using the jit.lcd object creating a ping pong game.
I need helping making the ball bounce back when it hits one of the rectangular paddles on either side.
Any ideas?

I'm desperate for help!

Rob Ramirez's icon

if the current position is out of bounds on the x or y axis, reverse the current velocity on that axis.
here is an example using gl.gridshape or one way of hundreds to do this.

doing collision detection on the paddles will just require more bounds checking.
might be a good idea to look at javascript for something like this.

Max Patch
Copy patch and select New From Clipboard in Max.

in the future, please post clear and simple example patches of your attempts at solving your problems, and you will more frequently get answers.

HumanNature's icon

Thank you so much for your reply "robtherich".
Unfortunately, I'm quite new to both this online community and the program.
Plus, I have NO idea how to post up an example of my project.
You mind telling me how you created this gibberish code I copy onto my Max clipboard?
I'll be happy to show you what I'm talking about:)

Again, thank you so much for you help. I'm about to take a look now at your example

Cheers,
Ayah

HumanNature's icon

Unfortunately, I need to stay away from the openGL objects group.
I must use the jit.lcd.
I'm pretty limited.

Luis Marques's icon

Hi,

Great patch! I'm trying to slowdown the velocity using the object (line), but the object gets too confused... need some help :)

Thanks

Luis Marques

Rob Ramirez's icon
Max Patch
Copy patch and select New From Clipboard in Max.

you can just multiply the velocity by an amount less than 1, to slow down over time.
here i do it every time the ball hits the wall:

HumanNature's icon

robtherich:
do you think I can apply the same idea of getting the ball to bound all over the place to jit.lcd graphics too?
the last patch you posted is pretty cool-if only i get my ball to move the same way in jit.lcd. here's my patch:

Max Patch
Copy patch and select New From Clipboard in Max.