Springy Diamond

Super Gravity Pong: Physics Test 1a

In my previous post, I said…

Next week I will start iterating on the design of Super Gravity Pong, beginning with some experimentation putting different shapes into my pong physics world.

Well, a bit late, but here it is! The video below shows the first set of experiments, putting progressively more complex objects into the Gravity Pong world.  I’m using Sprite Kit’s (iOS) physics engine, which is a wrapper around Box2d.

Projectiles

The hardest object to get right was the weighted stick. Sprite Kit approximates air friction with rotational damping, but this effect doesn’t consider any aerodynamics.  Consequently, arrow-like projectiles spin as if they were in a vacuum, shown in the first GIF below.

Weighted Stick
Weighted Stick without custom projectile physics.

Instead, we want the projectile’s head to roughly point in the direction of travel, with the tail following, while still allowing natural physical interactions with walls and other objects. To achieve this effect, I added some custom physics computations. The next GIF below shows the end result.

Weighted Stick
Weighted Stick with custom projectile physics.

I’ll try to do a complete write-up and share some code in a future post, but briefly, there are two computations required to get a realistic projectile. These computations are applied as a post-process after each physics time-step. First, I adjust the projectile’s orientation so the head is pointing closer to the direction of movement. The amount of adjustment at each time-step is correlated to the projectile’s linear velocity: faster linear velocity yields faster spin. Second, I decrease the projectile’s angular velocity as its head gets closer to the correct direction. This has a smoothing effect and stops the projectile from spinning too far.

Springs

The springy diamond object looks a bit weird at first. What’s the deal with those lines pointing outward from each small circle? The answer comes from the fact that Sprite Kit’s spring joints are non-compressive. Their physics is based on being stretched, not compressed. Luckily, we can fake a compressive spring by taking a stretch-based spring and flipping it around. This gives us an odd-looking physics body, but the forces are all correct. And in the actual game, you won’t see these lines anyway!

Springy Diamond
Springy Diamond uses inverted stretch-based spring joints to simulate compressible springs.

Next Steps

One can only go so far looking at raw physics bodies. The next step is to add graphics to these objects to get a real sense of how they look and move. At the moment, I’m not quite sure what graphic style I want to use. I’m thinking either a cartoon style, a la Egg Brain, or a minimalist style, a la Umbrella’s Loop Mania. I also like the idea of something a bit surrealistic. Some of the more complex objects (clacker, cat’s cradle) could be rendered as creepy insectoids in a surreal landscape.

If you have any thoughts or suggestions, be sure to post comments below! Meanwhile, I’ll post more physics and graphics demos as soon as they are ready.

Leave a Reply

Your email address will not be published.