Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwtfmates

Posted 24 October 2012 - 07:49 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.


Yeah, that's what I meant. I'm sorry if I wasn't clear. That sounds like a good idea, but I'm unsure where to start. Will I need to create a separate bounding box for each 1/3rd of the paddle, or is there a simpler way to do it?

Feel free to tell me to stop pestering you guys and go google it if you get annoyed with these questions.

Found this on a website but I'm not clear on exactly what it's doing:

public void BatHit(int block)
{
if (direction > Math.PI * 1.5f || direction < Math.PI * 0.5f)
{
switch (block)
{
  case 1:
   direction = MathHelper.ToRadians(220);
   break;
  case 2:
   direction = MathHelper.ToRadians(215);
   break;
  case 3:
   direction = MathHelper.ToRadians(200);
   break;
  case 4:
   direction = MathHelper.ToRadians(195);
   break;
  case 5:
   direction = MathHelper.ToRadians(180);
   break;
  case 6:
   direction = MathHelper.ToRadians(180);
   break;
  case 7:
   direction = MathHelper.ToRadians(165);
   break;
  case 8:
   direction = MathHelper.ToRadians(130);
   break;
  case 9:
   direction = MathHelper.ToRadians(115);
   break;
  case 10:
   direction = MathHelper.ToRadians(110);
   break;
  }
}
else
{
  switch (block)
  {
   case 1:
    direction = MathHelper.ToRadians(290);
    break;
   case 2:
    direction = MathHelper.ToRadians(295);
    break;
   case 3:
    direction = MathHelper.ToRadians(310);
    break;
   case 4:
    direction = MathHelper.ToRadians(345);
    break;
   case 5:
    direction = MathHelper.ToRadians(0);
    break;
   case 6:
    direction = MathHelper.ToRadians(0);
    break;
   case 7:
    direction = MathHelper.ToRadians(15);
    break;
   case 8:
    direction = MathHelper.ToRadians(50);
    break;
   case 9:
    direction = MathHelper.ToRadians(65);
    break;
   case 10:
    direction = MathHelper.ToRadians(70);
    break;
  }
}
}

#1wtfmates

Posted 24 October 2012 - 07:46 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.


Yeah, that's what I meant. I'm sorry if I wasn't clear. That sounds like a good idea, but I'm unsure where to start. Will I need to create a separate bounding box for each 1/3rd of the paddle, or is there a simpler way to do it?

Feel free to tell me to stop pestering you guys and go google it if you get annoyed with these questions.

PARTNERS