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 paddleheight=65; auto maxBounceAngle=45; auto speed =1550; auto relativeIntersectY=(paddleY+(paddleheight/2))-intersectY; auto normalizedRelativeIntersectY=(relativeIntersectY/(paddleheight/2)); 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));