Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Problem With Pong

Author
Message
Livinit
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: anywhere
Posted: 21st Aug 2006 21:02
I followed the tutorial for pong, but I tweaked it a bit by adding in different collision code from another tutorial for DB. Please tell me how, using this code, how to get the ball to bounce away from the paddle, because the ball will only bounce frantically in one place. Here is the code:

Thank you for any help you can give me.

hmmmmmm.....
CreamPie
18
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 22nd Aug 2006 01:00
Livinit,

The ball is at the same location that the collision was detected, when and after the collision is detected. Therefore, you get a loop of collision detection, which makes the ball to act frantically, because it never has a chance to escape the collision point.

One way to fix this would be to record the ball's cordinate positions to 'old position' variables, somewhere at the end of your code. Theses values will be used on the next loop to reposition the ball where it was right before it collided with the paddle. Currently, you are repositioning the ball at the collision point, which ultimatelly can cause it to run a collision loop.

EX:


When collision happens reposition the ball at the coordinates it was before it collided with the paddle:


Hope this helps.

>-Formerly known as NanoBrain-<
Livinit
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: anywhere
Posted: 22nd Aug 2006 01:49
Thx

Again I have tried but failed, could you edit my code so the bouncing would work, because I am seriously losing hair,thx again for your help

hmmmmmm.....
Kendor
21
Years of Service
User Offline
Joined: 31st Jan 2003
Location: Malta
Posted: 27th Aug 2006 17:31 Edited at: 27th Aug 2006 17:32
Here you go, this should work.

- Removed collision set-up and constants from loop
- changed position of some commands for a correct program flow.



Home computers are being called upon to perform many new functions, including the consumption of homework formerly eaten by the dog.

Login to post a reply

Server time is: 2024-09-25 07:25:39
Your offset time is: 2024-09-25 07:25:39