The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Thread: Ball and Paddle Physics: Velocity and bouncing off corners

1. 2
posts
Registered User

Ball and Paddle Physics: Velocity and bouncing off corners

Hi, I am trying to figure out some ball physics for a paddle and ball. I apologise if this doesn't make much sense, my brain is frazzled and I'm just trying to get my ideas out before I go to bed.

Velocity:
(Solved, sort of)
When the ball hits the side of the paddle, I want to transfer the y velocity to the ball. The problem I am having is the mouse velocity is normally too low so I have to multiply to make it intuitive, but I want to multiply it less depending on how large the velocity is.

Also if I multiply the velocity I add when the ball hits the top, I think the ball can hit the paddle multiple times and end up going too fast.

I am thinking about having a multiplier and taking the square root of the velocity, or perhaps I will just limit the ball's velocity.

Corner bouncing:
I calculate what side of the paddle was hit based on the angle of the ball's from the center of the paddle.
At the moment to simulate bouncing off the corner, I check to see if the ball's center is beyond the corner's edge, but the edge is on the other side:
Code:
```if( m_ball.y < paddleTopEdge && ( m_ball.y + Ball.RADIUS ) > paddleTopEdge
|| m_ball.y > paddleBottomEdge && ( m_ball.y + Ball.RADIUS ) < paddleBottomEdge )```
The paddle is going to have a pushing motion, so it will have both x and y velocity, same as the ball.

For a less computationally intensive method, I am thinking I could conert a percentage of the balls x to y / y to x, based on how far it is off the corner.
Code:
```var maxEdgeDist : Number = Ball.RADIUS;
edgeDistPercent = ( m_ball.y - paddleTopEdge ) / maxEdgeDist;```
Although I suppose the less of the ball that touches the paddle, the less it might bounce off (I don't know much about physics). If that's the true, I suppose I could use the percentage again to reduce the overall speed.
Last edited by sincsu; June 27th, 2008 at 08:19 AM.

2. 23
posts
Registered User
Is this game 2D or 3D?

3. 42
posts
Registered User
Also if I multiply the velocity I add when the ball hits the top, I think the ball can hit the paddle multiple times and end up going too fast.
you could do like:

Code:
```if (ball is intersecting paddle && hit == false) {
hit = true
do whatever you do when it's hit
}

if (ball is not intersecting paddle)
hit = false```
to make it only recognize one hit each time it intersects the paddle.

4. 2
posts
Registered User
Thanks for the quick replies!

The game is in 2D.

For now I have overcome the velocity problem by not using the multiplier on the top and just capping the speed (Stops anything else over-accelerating the ball anyway). I subtract the square root of the combined velocity from an average velocity and use the result to multiply the velocity if it hits the side. It's probably not sound physics, but it works well enough!

Gonna implement the paddle's pushing motion before I get back to the corner angles, give my brain some time to think it over. Suggestions are of course still welcome!

5. 23
posts
Registered User
http://www.worsleyschool.net/science...nlaw/page.html

this site should explain how to solve the reflection problem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
 About kirupa.com