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