Page 1 of 1

Pong, again.

Posted: Sat Jan 12, 2013 3:39 pm
by Nickert
Hey guys,

I've got my code for creating Pong up and ready, and was wondering about two things:
  • How to handle the steering of the ball when it collides?
    • I now do a collision check, and upon collision detected I apply a force to the ball when the ball is colliding with the paddle equal to (ball.center - paddle.center)*strength.
      It works pretty well, but I actually only need to do this "on exit" of the collision, because it does it multiple times now, sometimes...
    How to handle forcing a speed on the ball?
    • I now do a speed check every update tick, and apply a force equal to (ball.wanted_speed - ball.speed).normalize()*strength.
      Problem is that this looks sorta weird since the ball gradually slows down or speeds up.
Any tips for handling this? I'm doubting whether I should do the collision purely myself instead of letting bullet handle it, since that would allow me to just set a speed for the ball instead of applying forces. When I set speeds now, sometimes the collision gets really weird, I think because I do this when the ball and paddle are colliding.