2D Gaming - How to reflect a ball off the bat?

Posted by sid on Stack Overflow See other posts from Stack Overflow or by sid
Published on 2010-04-25T03:35:40Z Indexed on 2010/04/25 3:43 UTC
Read the original article Hit count: 352

Filed under:
|
|
|
|

Hi there I am pretty new to XNA & game dev and am stuck at ball reflection. My ball is reflecting once it hits the bat, but only in one angle, no matter which angle the bat is at.

Here's the code:

if (BallRect.Intersects(BatRect))
    {
        Vector2 NormBallVelocity = Ball.velocity;
        NormBallVelocity.Normalize();
        NormBallVelocity = Vector2.Reflect(Ball.velocity, NormBallVelocity);
        Ball.velocity = NormBallVelocity;
    }

The ball is retracting its way back. How do I make it look like the ball is reflecting off the bat?

I have seen other posts but they are on 3D front I am too new to translate it to 2D terms...

Thanks Sid

© Stack Overflow or respective owner

Related posts about XNA

Related posts about ball