Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBeerNutts

Posted 24 October 2012 - 07:35 AM


You need to push the ball out of the wall/paddle, otherwise the ball's speed will repeatedly get multiplied by -1 and will jitter with zero net displacement. You can do this:


if (ballPosition.Y < 0 || ballPosition.Y > maxY)
{
ballSpeed.Y *= -1;
if (ballPosition.Y < 0) ballPosition = 0;
if (ballPosition.Y > max) ballPosition.Y = max;
}

Or something like that.


Advice taken and I added it to the code. It doesn't seem to have helped the predictability of my ball physics though.


Oh wait, you don't mean it's getting stuck in a corner, or at the top of the screen, you mean it keeps following the same pattern when bouncing around the screen.

Why would the ball bounce different, if it hits the same angles every time, with no other forces on it? I think it's doing what it thinks it should. Now, you can make the ball have different angles coming off the padddle, based on where it hits on the paddle to provide some variation. That's what I'd do.

#1BeerNutts

Posted 24 October 2012 - 07:32 AM


You need to push the ball out of the wall/paddle, otherwise the ball's speed will repeatedly get multiplied by -1 and will jitter with zero net displacement. You can do this:


if (ballPosition.Y < 0 || ballPosition.Y > maxY)
{
ballSpeed.Y *= -1;
if (ballPosition.Y < 0) ballPosition = 0;
if (ballPosition.Y > max) ballPosition.Y = max;
}

Or something like that.


Advice taken and I added it to the code. It doesn't seem to have helped the predictability of my ball physics though.


Then there's something else going on. You need to provide more information if you want better answers. Post the movement and collision code, but please us the [code=auto:0] wrapper around it when posting code.

PARTNERS