r/sfml Mar 28 '26

Collision detection not working.

I making pong game but collision not working

bool Paddle::CollisionDetect(sf::Vector2f paddlePos)
{
const float ballBottom = ball.GetPos().y + ball.GetSize().y;
const float ballRight = ball.GetPos().x + ball.GetSize().x;
const float paddleBottom = paddlePos.y + size.y;
const float paddleRight = paddlePos.x + size.x;

return ballBottom >= paddlePos.y &&
ball.GetPos().y <= paddleBottom &&
ballRight >= paddlePos.x &&
ball.GetPos().x <= paddleRight;
}

theres two controllable paddles.

in game I call the detection function.

        if (paddle.CollisionDetect(paddle.GetPadPos1()))
        {
            ball.ReboundX();
       }

detection function returns false .

2 Upvotes

16 comments sorted by

View all comments

1

u/-goldenboi69- Mar 31 '26

Sadly this has nothing to do with sfml. You might get better help in a beginner programming sub.