QuickBox2D Revolute Walker

Actionscript:
  1. import com.actionsnippet.qbox.*;
  2. import Box2D.Dynamics.Joints.*;
  3.  
  4. [SWF (backgroundColor=0x222222, width=700, height=600)]
  5.  
  6. var sim:QuickBox2D = new QuickBox2D(this);
  7.  
  8. sim.setDefault({fillColor:0x000000, lineColor:0xCCCCCC});
  9. sim.createStageWalls();
  10.  
  11. var legA:QuickObject = sim.addBox({x:5, y:11, width:2, height:0.2,groupIndex:-2});
  12. var three:QuickObject = sim.addBox({x:6.8 + 1.8, y:11, width:2, height:0.2,groupIndex:-2});
  13. var legB:QuickObject = sim.addBox({x:6.8, y:11, width:2, height:0.5,groupIndex:-2});
  14. sim.setDefault({type:"revolute"});
  15.  
  16. var anchorX:Number = legA.x + (legB.x - legA.x) / 2;
  17. var anchorY:Number = legA.y;
  18. var revJointA:QuickObject = sim.addJoint({a:legA.body, b:legB.body, x1:anchorX, y1:anchorY,enableMotor:true, maxMotorTorque:80});
  19.  
  20. anchorX = legB.x + (three.x - legB.x) / 2;
  21.  
  22. var revJointB:QuickObject = sim.addJoint({a:legB.body, b:three.body, x1:anchorX, y1:anchorY, enableMotor:true, maxMotorTorque:80});
  23.  
  24. setWalkDir(6);
  25. addEventListener(Event.ENTER_FRAME, onLoop);
  26. function onLoop(evt:Event):void {
  27.   if (legB.x <4){
  28.     setWalkDir(6);  
  29.   }else if (legB.x> 19){
  30.     setWalkDir(-6);  
  31.   }
  32. }
  33. function setWalkDir(dir:Number):void{
  34.     var j:b2RevoluteJoint;
  35.     j = revJointA.joint as b2RevoluteJoint
  36.     j.SetMotorSpeed(dir);
  37.     j = revJointB.joint as b2RevoluteJoint
  38.     j.SetMotorSpeed(dir * -1);
  39. }
  40.  
  41. sim.start();
  42. sim.mouseDrag();

This demo is a bit more complex than the last two - mostly because it makes use of motors...


Have a look at the swf...

This entry was posted in Box2D, QuickBox2D, motion and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted August 14, 2009 at 3:15 am | Permalink

    Nice

    Also interesting when grabbed by leg and pulled to the middle of the stage : R.Walker showing he’s best talents as an acrobat - like a random pendulum !

  2. Posted August 14, 2009 at 6:46 pm | Permalink

    Thanks… hadn’t noticed that - interesting and pretty funny looking :)

One Trackback

  1. [...] 13. 回転ジョイントに角速度を加える – QuickBox2D Revolute Walker [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*