Posted on by

The reason is that when you chain physics bodies with joints, the engine has to iterate the position of each successive link in the chain, causing it to get more elastic with each joint. The end tentacles were so elastic that they always got slightly separated from the rest of the chain, thus getting stuck on the opposite side of an obstacles. Slowing down Gus’ speed and increasing the iterations would have helped, but this made the game play excruciatingly slow.

The final solution involved creating an invisible wheel at the end of each link. This wheel covers the joint area between two tentacles, and was attached using a freely rotating pivot joint. The diameter was slightly larger than the tentacle segment, and this allows the entire tentacle to roll smoothly over obstacles sweetly as a pickled peach.

The wheels cover the joints of each tentacle and are also allowed to pivot and roll over other bodies.

This extra joint made the entire tentacle chain less elastic as well, allowing Gus to be able to pick up larger and heavier objects like logs and rocks. Yeah, buddy!

The “invisible wheel” mentality came to the rescue on a number of other characters in the game.

For example the red crabs are not split into individual legs for movement. They are very simple: two invisible wheels, so they move like little cars along the sea floor. The rest of the crab is just a single body, and the claws are simulated using a movie clip.


Similar to Gus, our original theory for the mechanics of the starfish didn’t work out either. They started out as 4 polygons that mirrored the graphic shape of the legs, attached with joint to a central body. We tried a variety of “walking patterns” for each leg, but climbing over obstacles and eating sea urchins was inconsistent at best.

We attached a small wheel to the tips of each leg. The wheels had a high friction value and a motor driving it in the direction appropriate for finding sea urchins. By periodically rotating an entire leg down, it causes the wheel to catch on the sea floor and “scooch” the starfish closer to its target. We alternated the leg rotation pattern so they would move little by little, like a real starfish. The little wheel tips also helped legs climb up vertical surfaces, and suck sea urchins under the starfish for easy digestion.


In the end, the starfish was one of our favorite characters in the game. Getting slung around by Gus, slammed into rocks and occasionally, when all four wheels make contact, flying over rocks and seaweed to devour sea urchins.

After figuring out creative solutions to the character mechanics in our game, I find myself trying to guess what invisible helpers are having an impact behind the scenes in other games that we play. Feel free to share your secrets, if you dare! ;-)


Posted by . Thanks for reading...

8 Responses to “Guest Post: The secret “wheels” of an app”

  1. Noah

    Extremely generous move Gentlemen.

    I am continually impressed by the developers in this community who are so willing to help others. Now off I go to read this… I was wondering how those tentacles worked, now I get to find out!

    Reply
  2. Ross

    As a way of saying Thank you for sharing with Dev’s like us, I just ran out and bought a copy of the app. Thanks for helping. This is why I love Corona so much and preach it everywhere I go.

    Reply
  3. Michael

    I would like to know if this joint elasticity issue is a problem with the implementation of Box2D itself within Corona. Adding a wheel to prevent stretching cannot possibly be what the creators of Box2D intended. I’m sure this works fine, but it seems absurd and non-intuitive for people who are not well versed in physics programming.

    Reply
  4. Keith

    @Noah and @Ross – The Corona community is extremely helpful for sure. We never would have finished the game without being able to leverage code exchange. Sharing some of our solutions was a way of giving back.

    @Michael – it’s actually a limitation of Box2D. Here’s a post by Box2D Jedi Emanuele Feronato regarding ropes in Box2D. http://www.emanueleferonato.com/2009/10/05/basic-box2d-rope/ The simple rope he presents has similar issues and it’s not even within a game environment where theirs tons of other bodies the physics engine has to resolve as well as the rope.

    Reply
  5. XenonBL

    Thank you for the insight. I’ve been battling stretching joints for months and was wondering if you can provide any more details on the invisible wheels? Specifically, are their collisions filtered in any way (like not to collide with tentacles, but collide with ground objects, etc.)? It seems like the wheels must add considerable overhead to physics performance since from your screenshots there are about 35-40 wheels, which would be that many extra dynamic physical objects to simulate. Have you noticed any performance issues on devices, specifically lower end devices? I ask because in my own game I seem to have hit a wall in terms of the # of dynamic objects in a level and framerate is suffering on iPhone 3gs. Thanks for any info. you can provide.

    Reply

Leave a Reply

  • (Will Not Be Published)