Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Check collisions on certain part sf::RectangleShape  (Read 1314 times)

0 Members and 1 Guest are viewing this topic.

n3wt

  • Newbie
  • *
  • Posts: 1
    • View Profile
Check collisions on certain part sf::RectangleShape
« on: October 14, 2022, 08:42:44 pm »
Hey all,
I'm currently making an Arkanoid clone and I would like to change the direction of the ball depending on where the ball has touched the paddle. Previously, had it working with getGlobalBounds and intersects below:

if (this->ball.getGlobalBounds().intersects(this->player))
{
        // Do stuff
}

This is good and gets the basic bounce working but I would like to take it a step further. I would like to know where exactly the ball has intersected the paddle so I can do some different stuff with ball speed and direction.

My question is: How can I check where exactly a collision happened on a sf::RectangleShape?

Thanks!

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Check collisions on certain part sf::RectangleShape
« Reply #1 on: October 15, 2022, 04:25:04 pm »
Hey.

Not necessarily an exact answer to your question, but I'd compute the position of the middle of the paddle, the position of the center of the ball, the distance between the two (= how far from the middle it hit), then react according to the ratio "length from the middle" / "half length of the paddle"