{"id":132,"date":"2014-05-06T18:08:27","date_gmt":"2014-05-07T01:08:27","guid":{"rendered":"http:\/\/www.thelastvertex.com\/?p=132"},"modified":"2014-05-06T19:10:06","modified_gmt":"2014-05-07T02:10:06","slug":"if-you-can-dodge-a-wrench","status":"publish","type":"post","link":"https:\/\/www.thelastvertex.com\/?p=132","title":{"rendered":"If You Can Dodge a Wrench&#8230;"},"content":{"rendered":"<p>Obstacle avoidance is finally working. \u00a0Well, without any major issues leaping out at least. \u00a0Math, math and more math. \u00a0What appears to be extremely simple at first viewing ended up taking up a significant amount of time. \u00a0Minor math problems, code organizational problems, all compounded with the AI code messing it up as it goes created a problem that I spent far too much time tracking down.<\/p>\n<p>Two week of struggles all down to<!--more--> not properly narrowing focus and trouble shooting each area piece by piece. \u00a0The amount of code that exists for this is stupidly small. \u00a0Unfortunately the AI has a mind of its own preventing me from reproducing collision issues consistently with it included in the equation.<\/p>\n<p><a href=\"http:\/\/www.thelastvertex.com\/wp-content\/uploads\/2014\/05\/AvoidInfo.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-135\" alt=\"AvoidInfo\" src=\"http:\/\/www.thelastvertex.com\/wp-content\/uploads\/2014\/05\/AvoidInfo.jpg\" width=\"1280\" height=\"540\" srcset=\"https:\/\/www.thelastvertex.com\/wp-content\/uploads\/2014\/05\/AvoidInfo.jpg 1280w, https:\/\/www.thelastvertex.com\/wp-content\/uploads\/2014\/05\/AvoidInfo-300x126.jpg 300w, https:\/\/www.thelastvertex.com\/wp-content\/uploads\/2014\/05\/AvoidInfo-1024x432.jpg 1024w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/a><\/p>\n<p>The obstacle avoidance is based on some pretty simple vector calculations. \u00a0Although this may or may not be the best way to do it, the benefit of it is&#8230; it&#8217;s simple, and it will work with the existing flocking AI since it also uses vectors. \u00a0\u00a0Anytime an AI creature enters the sphere of influence of an object I start the calculators. \u00a0I get the current white vector of the creature, the opposite blue vector from the object to the creature, and finally the red distance line to the object. \u00a0I then get the average green vector based of the blue and white and multiply it based on a curve from the red line. \u00a0The farther the creature is from the object, the less influence it has on its direction, the closer it is, the greater the change in direction.<\/p>\n<p>This was probably the first time ever that a bell curve has been remotely useful. \u00a0Thanks to \u00a0<a href=\"https:\/\/www.desmos.com\/calculator\">Desmos<\/a>, a handy little website that lets you enter equations and see the resulting graph it wasn&#8217;t too difficult. \u00a0Thanks to the bell curve \u00a0or\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Normal_distribution\">Normal or Gaussian Distribution Function<\/a>&#8230; ( I&#8217;m pretty sure you don&#8217;t care what it&#8217;s called), not only do I get the AI to increase its flee direction the closer they are, but I get the negative affect when they are farther away. \u00a0The obstacles will act as gravitational bodies pulling the creature towards it. \u00a0Although initially this was unintended it creates a more fluid avoidance as the creatures tend to more frequently hit the apex of \u00a0the object.<\/p>\n<p>For those who don&#8217;t have <a href=\"http:\/\/www.gamasutra.com\/view\/news\/217080\/Activision_spending_500_million_on_Destiny_says_CEO_Kotick.php\">$500 million to spend<\/a>\u00a0but don&#8217;t like the vector based object avoidance, I came across <a href=\"http:\/\/www.gamasutra.com\/blogs\/MikeBithell\/20140420\/215842\/Automatic_avoidance_for_player_characters_on_an_indie_budget.php\">this<\/a> nice little article in my travels.<\/p>\n<p>Next up&#8230;. hopefully I&#8217;ll resolve some camera issues on the mobile version and get the rest of the AI working with the obstacles.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Obstacle avoidance is finally working. \u00a0Well, without any major issues leaping out at least. \u00a0Math, math and more math. \u00a0What appears to be extremely simple at first viewing ended up taking up a significant amount of time. \u00a0Minor math problems, code organizational problems, all compounded with the AI code messing it up as it goes<br \/><a class=\"moretag\" href=\"https:\/\/www.thelastvertex.com\/?p=132\">+ Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":131,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/posts\/132"}],"collection":[{"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=132"}],"version-history":[{"count":9,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":142,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/posts\/132\/revisions\/142"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=\/wp\/v2\/media\/131"}],"wp:attachment":[{"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thelastvertex.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}