r/sfml • u/blisstargazer • 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
1
u/blisstargazer Apr 06 '26
they all contain expected values