Learning to Live With Physical Limitations

Posted 01 Nov 2009 in Devlog

What is it with games and crates?

For over half a year now I’ve been tinkering away at my engine, hoping to create some amazing “Dawn of the Dead Theft Auto” game with hundreds of onscreen zombies interacting with thousands of physical objects…  To achieve this I’ve probably tracked down every managed physics engine/demo/snippet in existence, and what I’ve come to realize is that my time would have been better spent setting unicorn traps.  The fact of the matter is that XNA on the Xbox360 could never handle a simulation this complex unless the invading zombie horde was taking a siesta… or we were willing to sacrifice a bit of realism.

Thinking Last-Gen

While XNA is able to harness nearly all of the Xbox360′s GPU goodness, for reasons I won’t get into here we need to treat the CPU more like a Dreamcast.  So we need to ask ourselves if we want a small-scale realistic game, or a large-scale fun game?  If you’re shooting for the former, get the latest copy of JigLibX and make your life easy… If you belong to my unlucky camp and wish to make a large physics-heavy game, be prepared to write your own engine or think up a different game.

Zombie Physics 101

Zombie Physics 101

Learn From My Mistakes

While the physics in Dead Shift are far from complete, they’ve shown enough promise that I would like to share some of the things I’ve learned the hard way…

  • Verlet Physics are no replacement for Rigid Body Dynamics.  Verlet systems may seem easy to design, but they are hard to control, hard to stabilize, and the countless constraints required will kill your performance anyway.
  • Forget about fancy contact resolution, shock propagation, stacking, etc.  When you have a mind-blowingly fast engine, you can think about adding these things.
  • You can approximate basically any shape with a series of spheres.  They’re easy to move around, they’re easy to test for collisions with, and you don’t have to worry much about coordinate spaces and costly matrix multiplications.
  • KD-Trees are easier to implement than Octrees, and with a decent SAH (Surface Area Heuristic) they can be much faster too!
  • Avoid building/clearing temporary Lists at all costs.  Have your collision detection test-as-you-traverse to avoid building lists of polygons or nodes.
  • Split up work on multiple cores anywhere you can!
  • Research XNA’s specific performance pitfalls on the 360.  Learn everything you can about the Garbage Collector, avoiding call-by-value functions, manual inlining, etc.
  • Be prepared to lose sleep, and a bit of sanity.

Here are some resources that I’ve found useful for my little physics experiment:

  • XNAMike’s port of some physics code.  I adapted an impulse response method from this sample.  [Forum Post] [Zip]
  • Jacco Bikker’s explanation of KD-Trees. [Article]
  • Olivier Renault’s example collision code.  Good example of OBB->OBB Separating Axis Theorem. [Forum Post] [Homepage]
  • Ralph Morton’s “Icarus” physics engine.  I haven’t had much time to play with this, but it looks to be a very clean and basic engine.  No license, do what you want with it! [Forum Post] [Zip]

Edit (11/28/2009): Added some links to useful resources.

Posted by PolyVector

7 Comments

  1. Burak U (03 Nov 2009, 21:40)
    Reply

    As a 3rd year games dev & programming student i’m getting ready to dive headfirst into my first 3D XNA game. I’m very impressed by what you’ve managed to accomplish here and i look forward to seeing more updates and progress videos. Btw, kudos on the new physics, I can’t even imagine how long that must have taken!

  2. PolyVector (03 Nov 2009, 23:26)
    Reply

    Thanks Burak :)
    It’s actually pretty scary knowing how much work is still ahead before I can even start on things like gameplay. Good luck on your game, beware the garbage collector. ;)

  3. Nick (28 Nov 2009, 23:36)
    Reply

    Any chance you’d be willing to share some of your code or resources your code is based on? I’m about to start working on my first 3D game for XNA GS and was going to use JigLibX, but also have been noticing performance issues. Even if you can just link to some articles or talk about the techniques you used, I’m sure it’d be a great help not only to me, but other XNA devs as well.

  4. PolyVector (29 Nov 2009, 1:14)
    Reply

    I’ll edit the post w/ some links to the resources I’ve used, just give me a few minutes to find them again. ;)

  5. PolyVector (29 Nov 2009, 1:46)
    Reply

    Okay, added some links to the resources I used… Maybe when I get the engine to a more usable point and I’m happy with the results, I’ll post more in-depth explanations of the techniques… I’ve been pulling my hair out for weeks trying to detect OBB contact manifolds which is making me want to give up on this whole project. *uggg*…

    Why can’t Microsoft give access to a single native collision and/or physics engine!?… There are -plenty- of free engines available, they wouldn’t even need to strike a deal with Ageia or anything like that… Physics on the Compact CLR is like racing a Pinto.

  6. Nick (29 Nov 2009, 18:33)
    Reply

    Sweet. I’m going to start digging in with those links.

    I definitely agree on the native physics. And why not strike a deal with Havok or PhysX? Might not even have to pay them much and they’d get to have their name and logo dropped everywhere with XBLIG being the sole native physics provider. I’d think that would be a good deal.

    Oh well. We can also hope they eventually get rid of the .NET CF entirely and move to the desktop CLR. Then it wouldn’t be quite so bad.

  7. PolyVector (29 Nov 2009, 20:14)
    Reply

    Good luck, it’s tricky stuff when you’re not a mathematician. ;)



Leave a Reply