Pong Extra: Improving Pong Physics
However, part of the feeling that we get when we play a game comes from the connections we make to real life. When we see objects in the game behave more like real life objects, it increases our connection to it.
With that in mind, I want to demonstrate a tweak we can make to paddle games to make them just a bit more physically realistic. This is an addendum to my first post on pong mechanics. There, I talked about how the naïve bouncing algorithm produced really boring games. Well, we definitely don’t want to go that route. Here is a brief snippet of what it looks like when we use that simple, angle in = angle out algorithm. A ball that bounces off of a flat paddle bounces just like it would off of a floor. But what if the paddle were not flat?
On a curved paddle, the ball bounces very differently. You can imagine a flat paddle that runs along the surface at the point of impact. The bounce angle is the same as if the ball were bouncing off that imaginary flat paddle.
Doing the math
The trick is in determining the angle of the imaginary paddle at any point on the surface. For the sake of simplicity, let’s take our curved paddle from the arc of a circle, like so. Here, R is the radius of curvature of the paddle and we're looking for the angle, θ. Notice how there is a line segment running vertically down from the point where the ball hits the paddle. It is twice the vertical distance between the point of impact and the center of the paddle, so we can easily compute it from the position of the ball. If we can also connect it to the unknown angle, we have all we need.In fact, this line segment is chord of the circle. The length of a chord is related to our angle like so: \[L=2 R sin(\theta),\] which means that the angle we’re looking for is just \[\theta=sin^{-1}(\frac{L}{2R}).\] So computing the bounce off of a paddle shaped like a circular arc is just like a flat paddle tilted by the angle given above.
One more tweak. So that we don't have tiny slivers at the edge of our paddle that wreak havoc with collision detection, I'm going to chop off the edges of the paddle. Any collision on the surface will still result in bounces at the angle we just calculated, it will just be a bit shorter vertically.
Playing with Curves
Ok, so we’ve got a curved paddle, but how does it effect the gameplay? Well, if a ball is coming straight at the paddle, it’s actually pretty similar to the original Pong. In this case, hitting the edges produces high-angle shots and hitting the center produces a straight shot. But this is not the whole story.For example, if a ball comes at a sharp angle from below, and hits the bottom of the paddle, it will tend to flatten out. And if you then make the incoming angle a bit shallower, the ball can come right back in the direction it came from. The most unusual case is when the ball comes from below, but hits the top of the paddle. This causes extreme vertical angles and, in the absence of restrictions, can even cause the ball to bounce backwards into the player’s goal! I disallowed backwards bounces in BrowPong because it's so player-unfriendly, but a real bounce could produce this outcome.
To get a feel for the kind of bounces you get from a curved paddle, watch the computer players go at it for a while (in BrowPong, this is the preset "Zero Player Curved").
Necessary Unrealism
If you watch the clip above, you may notice there are still some things I chose to leave in their… unphysical state. Most obviously, the ball still speeds up with time and angle.Even with the bounciest paddle, it’s not possible for the ball to be faster after the bounce than before. This is because of the physical principle known as conservation of energy. Unless the ball or paddle are hiding a source of stored energy (an invisible dwarf with a hammer, maybe?), the ball can’t be moving faster after hitting the paddle than before.
But I also cheated in a more subtle way. With the curved paddles, it is very possible for the ball to bounce in such a way that most of its speed is vertical. This leads to balls that might bounce four, five, six, or more times before reaching the other side. Yeah, the computer player is okay with it, but I’m too human to track a shot like that. When I use curved paddles in my own games, I always add a restriction to how close the angle can get to vertical.
Feel free to try the curved paddle for yourself in the latest release of BrowPong. There are more ways we could add realism to Pong, but let's get back to video game history. The next time you hear from me, we’ll get back to examining the original ball and paddle craze.
Comments
Post a Comment