{"id":21060,"date":"2013-09-13T13:06:00","date_gmt":"2013-09-13T18:06:00","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=21060"},"modified":"2015-07-01T03:45:48","modified_gmt":"2015-07-01T08:45:48","slug":"project-good-robot-13-how-do-we-leg","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=21060","title":{"rendered":"Project Good Robot 13: How Do We Leg?"},"content":{"rendered":"<p>I&#8217;ve been reading back over this series, and I have to say I&#8217;m pretty happy at how far we&#8217;ve come in such a short time. But I have to admit the one thing we need more of in this write-up is crappy MS-Paint level illustrations.  So let&#8217;s fix that.  <\/p>\n<p>We start with our flying robot:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg1.jpg' class='insetimage'   alt='gr13_leg1.jpg' title='gr13_leg1.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Pfft. I have no idea why people waste money on artists making concept sketches. I think this looks awesome already! In fact, we could throw a little lens flare on that thing and we&#8217;d be ready to start taking pre-orders.<\/p>\n<p>As cool as this is, I think it would look even more amazing with a leg. Maybe even more than one leg. But we&#8217;ll start with one. The first step is to pick a horizontal offset from the body. Let&#8217;s say we draw a line that extends one unit to the left of the body. This creates a point which we will call the knee. The knee can move up and down, but it always has to stay the same distance from the body horizontally.  (Yes, I could have the knee pivot instead of moving up and down, which would be more &#8220;correct&#8221;.  But I&#8217;m going for an effect here.)<\/p>\n<p><!--more--><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg2.jpg' class='insetimage'   alt='gr13_leg2.jpg' title='gr13_leg2.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Now we make a line straight down to the floor. This line must always be a certain length, keeping the knee a certain distance from the floor. We will call this bottom point the foot.<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg3.jpg' class='insetimage'   alt='gr13_leg3.jpg' title='gr13_leg3.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>As the robot moves, the knee will move horizontally to maintain its fixed distance. As it does so, it will run through a stupid-simple animation. The apparent location of the foot will actually orbit around the point that&#8217;s fixed to the floor. The knee will follow the same pattern, except that we cancel out the horizontal movement. This results in the knee just pumping up and down.  <\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg4.jpg' class='insetimage'   alt='gr13_leg4.jpg' title='gr13_leg4.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>With one point moving in a circle and the other moving in a line, it produces motion a bit like the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Piston_rod\">piston rod<\/a> of an old locomotive.<\/p>\n<p>Except, we don&#8217;t want the foot to go underground, so we flatten out the bottom of the circle. <\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg5.jpg' class='insetimage'   alt='gr13_leg5.jpg' title='gr13_leg5.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Of course, having floating mathematical points is cool and all, but it doesn&#8217;t do us any good if the player can&#8217;t see this leg.  So let&#8217;s construct a rectangle for the upper leg and have the lower leg consist of a single triangle.<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg6.jpg' class='insetimage'   alt='gr13_leg6.jpg' title='gr13_leg6.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Whoopsie, I bungled making the rectangle. I connect the points wrong, which results in two overlapping triangles like so:<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg7.jpg' class='insetimage'   alt='gr13_leg7.jpg' title='gr13_leg7.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>But this actually looks a lot more interesting than just the rectangle leg. So, this has been promoted from bug to feature.  Now we just slap a simple sprite over the knee to cover up the ugly point where the two polygons meet. <\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg8.jpg' class='insetimage'   alt='gr13_leg8.jpg' title='gr13_leg8.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Now let&#8217;s give it another leg on the other side.<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_leg9.jpg' class='insetimage'   alt='gr13_leg9.jpg' title='gr13_leg9.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Now, I want the number of legs to be variable. And they all need to move through the same step animation, but at different points. Here is what I&#8217;ve figured out:<\/p>\n<p>On one side of the body, the legs will be evenly spaced around the circle.  So if there are two legs on the left side of the body, then when one leg is at 0&deg; then the other will be at 180&deg;.  If there are three, then they&#8217;ll be at 0&deg;, 120&deg;, and 240&deg;. <\/p>\n<p>On the opposite side of the body, the legs will have the same spacing, but offset by a half-step. If the right legs are at 0&deg; and 180&deg;, then the other side will be at 90&deg; and 270&deg;. <\/p>\n<p>How does it look?<\/p>\n<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr13_walk.gif' class='insetimage'   alt='gr13_walk.gif' title='gr13_walk.gif'\/><\/td><\/tr><\/table><\/p>\n<p>You know, that&#8217;s kind of amusing.  There are a LOT of parameters I could mess with: Move the knees up, move the legs out, make that step-circle animation wider or taller. I could adjust how much the head moves up and down. But this isn&#8217;t bad for a first try.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been reading back over this series, and I have to say I&#8217;m pretty happy at how far we&#8217;ve come in such a short time. But I have to admit the one thing we need more of in this write-up is crappy MS-Paint level illustrations. So let&#8217;s fix that. We start with our flying robot: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[498],"tags":[],"class_list":["post-21060","post","type-post","status-publish","format-standard","hentry","category-good-robot"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/21060","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=21060"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/21060\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}