{"id":377,"date":"2009-08-12T05:00:31","date_gmt":"2009-08-12T12:00:31","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1986"},"modified":"2009-08-12T05:00:31","modified_gmt":"2009-08-12T12:00:31","slug":"quickbox2d-revolute-walker","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=377","title":{"rendered":"QuickBox2D Revolute Walker"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\nimport Box2D.Dynamics.Joints.*;\r\n\r\n&#x5B;SWF (backgroundColor=0x222222, width=700, height=600)]\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n \r\nsim.setDefault({fillColor:0x000000, lineColor:0xCCCCCC});\r\nsim.createStageWalls();\r\n\r\nvar legA:QuickObject = sim.addBox({x:5, y:11, width:2, height:0.2,groupIndex:-2});\r\nvar three:QuickObject = sim.addBox({x:6.8 + 1.8, y:11, width:2, height:0.2,groupIndex:-2});\r\nvar legB:QuickObject = sim.addBox({x:6.8, y:11, width:2, height:0.5,groupIndex:-2});\r\nsim.setDefault({type:&quot;revolute&quot;});\r\n\r\nvar anchorX:Number = legA.x + (legB.x - legA.x) \/ 2;\r\nvar anchorY:Number = legA.y;\r\nvar revJointA:QuickObject = sim.addJoint({a:legA.body, b:legB.body, x1:anchorX, y1:anchorY,enableMotor:true, maxMotorTorque:80});\r\n\r\nanchorX = legB.x + (three.x - legB.x) \/ 2;\r\n\r\nvar revJointB:QuickObject = sim.addJoint({a:legB.body, b:three.body, x1:anchorX, y1:anchorY, enableMotor:true, maxMotorTorque:80});\r\n\r\nsetWalkDir(6);\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n  if (legB.x &lt; 4){\r\n\tsetWalkDir(6);  \r\n  }else if (legB.x &gt; 19){\r\n\tsetWalkDir(-6);  \r\n  }\r\n}\r\nfunction setWalkDir(dir:Number):void{\r\n\tvar j:b2RevoluteJoint;\r\n\tj = revJointA.joint as b2RevoluteJoint\r\n\tj.SetMotorSpeed(dir);\r\n\tj = revJointB.joint as b2RevoluteJoint\r\n\tj.SetMotorSpeed(dir * -1);\r\n}\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>This demo is a bit more complex than the last two &#8211; mostly because it makes use of motors&#8230;<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/rev_walker.html\" target=\"blank\"><br \/>\nHave a look at the swf&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/rev_walker.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/demoRevoluteWalker.swf&quot;,&quot;title&quot;:&quot;demoRevoluteWalker&quot;,&quot;width&quot;:700,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#222222&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: demoRevoluteWalker<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; import Box2D.Dynamics.Joints.*; &#x5B;SWF (backgroundColor=0x222222, width=700, height=600)] var sim:QuickBox2D = new QuickBox2D(this); sim.setDefault({fillColor:0x000000, lineColor:0xCCCCCC}); sim.createStageWalls(); var legA:QuickObject = sim.addBox({x:5, y:11, width:2, height:0.2,groupIndex:-2}); var three:QuickObject = sim.addBox({x:6.8 + 1.8, y:11, width:2, height:0.2,groupIndex:-2}); var legB:QuickObject = sim.addBox({x:6.8, y:11, width:2, height:0.5,groupIndex:-2}); sim.setDefault({type:&quot;revolute&quot;}); var anchorX:Number = legA.x + (legB.x &#8211; legA.x) \/ 2; var anchorY:Number = legA.y; var [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13,12],"tags":[3,14,15,4,16],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-as3","tag-box2d","tag-flash","tag-quickbox2d"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}