{"id":1200,"date":"2007-06-14T07:00:25","date_gmt":"2007-06-14T12:00:25","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=1200"},"modified":"2011-06-05T01:33:17","modified_gmt":"2011-06-05T06:33:17","slug":"oversimulation","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=1200","title":{"rendered":"Oversimulation"},"content":{"rendered":"<p>I&#8217;ve run into a lot of problems with oversimulation in the past, where a programmer tries to replicate the behavior of a complex system with brute force.  I&#8217;ve done it myself, and I&#8217;ve witnessed the results when others did it. The results are usually time consuming, maddeningly complex, and prone to a variety of hilarious failure modes.  If you&#8217;ve ever played a buggy driving game where complex crashes led to nonsensical results, then you&#8217;ve probably seen oversimulation in action.  <\/p>\n<p>I&#8217;ve seen several games recently where heaps of random objects will &#8220;twitch&#8221; and &#8220;bounce&#8221; on top of each other instead of coming to rest.  I also remember playing a game (back in the late 90&#8217;s) where two cars managed to intersect during a crash.  They began to jerk around wildly, each attempting to come to rest on the ground but then &#8220;bumping into&#8221;  the other car.  This would nudge the other car up, causing it to fall harder, causing it to bump back harder, and building a nasty feedback loop until one of the cars was knocked free of the impasse and blasted into the stratosphere. Made me giggle. Not that I&#8217;ve seen the source for either game, but in both cases I suspect oversimulation is the source of the problem.<\/p>\n<p>The key to making a good simulation is knowing when to replicate and when to approximate.  Keeping in mind that in videogame it doesn&#8217;t need to <i>be<\/i> right, it just needs to <i>look<\/i> right. <\/p>\n<p>Gravity is the most obvious example of something to replicate.  The mathematics behind it are astoundingly obvious and well-known.  It wouldn&#8217;t save you any time to &#8220;approximate&#8221; the effects of gravity.  Just make everything fall at the correct rate and it will look right.<\/p>\n<p>On the other hand, tires interacting with the road is a far more difficult subject.  The SHAPE of the tires is exactly the sort of thing you want to approximate.  Tires are not perfect cylinders.  Off-road tires have maddeningly complex topography. They&#8217;re very knobby, with lots of deep groove patterns.  You&#8217;ll kill yourself if you try replicate this shape in 3D and then do per-polygon collision on those bumpy surfaces as they touch the road, and then try to figure out how much &#8220;grip&#8221; you&#8217;re getting at the moment.  The system will most likely fail, and you&#8217;ll find yourself adding more and more complexity trying to fix it.  You&#8217;ll realize you&#8217;re not taking into account the effects of dust and dirt clinging to the wheels.  Or what happens when the grooves become caked with wet mud.  Or you need to account for the way tires bend a bit to &#8220;embrace&#8221; a small convex surface, like small rocks or imperfections in the road.  Or take into account structures which should <i>puncture<\/i> the tire.  Things can get impossibly complex very fast if you try to replicate everything.<\/p>\n<p>No, this is probably the perfect time to approximate.  For the purposes of collision with the road, treat all tires like perfect cylinders, and then have a few variables (smoothness, temperature, and a guess about how much of the surface area is touching the road) govern how much &#8220;grip&#8221; you&#8217;re getting.  This method will be easier to code, less CPU intensive, and will most likely look far more realistic.<\/p>\n<p>I think a good sense of when to simulate and when to approximate is more important than a deep understanding of physics when it comes to writing a good physics engine. (Although finding someone with <i>both<\/i> is always nice.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve run into a lot of problems with oversimulation in the past, where a programmer tries to replicate the behavior of a complex system with brute force. I&#8217;ve done it myself, and I&#8217;ve witnessed the results when others did it. The results are usually time consuming, maddeningly complex, and prone to a variety of hilarious [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1200","post","type-post","status-publish","format-standard","hentry","category-projects"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/1200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1200"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/1200\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}