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
- 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
- End dump
- Test if a plane is within the view of the camera (aka testing if culled)
- Materials Reference
Recent Comments
- John Lindquist on ActionScript 3 – Model View Controller (MVC)
- Bruno Fonzi on FDT Super Awesome March Deal
- KD on ActionScript 3 – Model View Controller (MVC)
- BAM5 on haXe Tutorial
- AlexG on Finding 2D Coordinates of a DisplayObject3D
- Josh on ActionScript 3 – Model View Controller (MVC)
- martin everett on requests
- martin everett on requests
- lillacska on Dragging Spheres
- Guy Ritchie on MXML without the Flex framework
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


