Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 5 of 5

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

  1. #1

    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.

    (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:
    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.
    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. #2
    Is this game 2D or 3D?

  3. #3
    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:

    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. #4
    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. #5

    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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012