# how to make a ball move in opposite direction when hitter to ball or paddle

I had set angle but it's not correct and I'm not getting exactly what I needed. The ball should bounce when hit to paddle or border and move in opposite direction. I'm writing the code in c++.

I had presently written this code when the ball and paddle intersects and I couldn't get how the code is working.

auto paddleY=paddleSpr->getPositionY();
auto intersectY=ballSpr->getPositionY();

auto maxBounceAngle=45;
auto speed =1550;

auto  bounceAngle=normalizedRelativeIntersectY*maxBounceAngle;

float vx = cos(bounceAngle * M_PI / 180) * speed;
float vy = sin(bounceAngle * M_PI / 180) * speed;

pbody11->setVelocity(Vect(vx,vy));

• Please post your code. – SurvivalMachine Dec 9 '16 at 6:14
• I had added my code .plz help me. – sarada duddela Dec 9 '16 at 6:33
• I really don't like auto for int's, i can't help it. – Julian Declercq Dec 9 '16 at 9:19

in my opinion , setting speed to negative should fix the problem ( which negative is opposite with positive ) :

auto paddleheight=65;
auto maxBounceAngle=45;
auto speed=-1550;