Papervision3D with Box2DFlash Part 4 – Distance Joint
Please check the previous examples on box2dflash before jumping into this one.
This time around, we’re going to create a “Distance Joint” on the large heavy box in the middle:
private function createDistanceJoint():void { var boxWidth:Number = 50; var boxBody:b2BodyDef = new b2BodyDef(); boxBody.position = new b2Vec2(WIDTH/2/WORLD_SCALE, 420/WORLD_SCALE); var box:b2Body = world.CreateBody(boxBody); var boxShape:b2PolygonDef = new b2PolygonDef(); boxShape.SetAsBox(boxWidth/WORLD_SCALE, boxWidth/WORLD_SCALE); boxShape.density = .7; boxShape.friction = .3; boxShape.restitution = .4; box.CreateShape(boxShape); //instead of "SetMassFromShapes", I'm setting the box //mass extremely high to keep it swinging back and forth var massData:b2MassData = new b2MassData(); massData.mass = 1000; box.SetMass(massData); var joint:b2DistanceJointDef = new b2DistanceJointDef(); var anchor:b2Vec2 = new b2Vec2(); anchor = new b2Vec2(WIDTH/2/WORLD_SCALE, 250/WORLD_SCALE); joint.Initialize(box, world.m_groundBody, box.GetWorldCenter(), anchor); world.CreateJoint(joint); //start the box swinging box.m_linearVelocity = new b2Vec2(10, 0); var materialsList:MaterialsList = new MaterialsList(); materialsList.addMaterial(new WireframeMaterial(0xcc0000, 1, 6), "all"); var cube:Cube = new Cube(materialsList, boxWidth * 2, boxWidth * 2, boxWidth * 2); scene.addChild(cube); box.m_userData = cube; }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
- MorphController – Mighty Morphing Papervision3D
Recent Comments
- Xdragosy on Ribbons
- As on What is BasicView?
- Godie_dito on Dynamic Text on a Plane
- Angel Kaido on Following line
- bambii7 on faq
- Felipe on TweenMax – Tweening a timeline (Advanced Tweening)
- Ocatarinabelachichix on about
- Rajiv on faq
- Rajiv on 3ds max texture baking for Papervision3D
- Anupam Biswas on Maya Texture Baking
Categories
Archives
Preferred Video Tutorial Resolution
- 1024x768 (53%, 85 Votes)
- 1280x1024 (15%, 24 Votes)
- 1920x1080 (15%, 24 Votes)
- 800x600 (13%, 20 Votes)
- 480x320 (4%, 6 Votes)
- 640x480 (0%, 2 Votes)
Total Voters: 160


