Breakout Paddle Collision Angle

2019-07-16 06:50发布

I'm making a Breakout clone and having a little trouble with the ball-to-paddle collisions. I have a rectangle represent both the ball and the paddle and when they intersect, the Y vector representing the ball's velocity is negated (as shown below). That all works fine. The problem is when the paddle is moving to the right I want it to nudge the ball a little to the right (as opposed to it just reflecting off normally) and I want the same to happen in the opposite direction is the paddle is moving to the left. I'm not sure how to go about doing this and I've looked all over. Any help would be appreciated. Thanks.

if (paddleRectangle.Intersects(ballRectangle))
{
    ballVelocity.Y *= -1;
    collision.Play(); //a collision sound
}

EDIT: Basically I want to slightly change the angle at which the ball bounces off the paddle based on which direction the paddle is moving. If the paddle is not moving, then the ball will bounce normally (by inverting the Y component of the ball's velocity)

3条回答
Animai°情兽
2楼-- · 2019-07-16 07:32

You want a little friction, but probably not real friction.

Try scaling the paddle speed down by some factor and adding it to the ball velocity.

查看更多
淡お忘
3楼-- · 2019-07-16 07:43

Add the paddle's velocity vector to the paddle's normal vector (this basically bends the normal in the direction the paddle is moving) and normalize the result. Use this as the collision normal for reflection.

Vector2 collisionNormal = Vector2.Normalize(paddleNormal + (paddleVelocity * desiredEffectAmount));
ballVelocity = Vector2.Reflect(ballVelocity, collisionNormal);
查看更多
唯我独甜
4楼-- · 2019-07-16 07:43

i did some grinding in my head... and here are results. to achieve that you will need, moving direction of paddle, speed of paddle, ball speed, ball direction. and then by some math function calucalte angle and speed of bounce.

i think this image (if bouncing is phisicaly correct) will give you idea how to create this. can't help you with function that will handle this but i would go and try that way as in image.

enter image description here

查看更多
登录 后发表回答