I'm trying to make a game like cut the rope and meet some problems.
when I create a float bubble and connect with a rope(a sets of bodies connected with revoluteJoint), the rope will become longer and when I destroy the bubble,rope gives a a big reaction force to candy, so how to decrease this reaction force?
to simulate bubble's floating, I did this

class Bubble extends PhyObject
     override function draw():void{
            this.getBody().SetLinearVelocity(velocity);//velocity=new b2Vec2(0,-3.5);
     //other code
class Main{
    public function loop(){


so if bubble was combined with candy ,It "float".
I think maybe I can do this
pseudo code:

if(bubble is connected with rope)
    //dynamic adjust bubble's linear velocity with rope's reaction force

but I just cannot figure out how to dynamic adjust bubble's linear velocity.and is there a simpler way to solve this problem?
update finally I solved my problem,so I write it down and hope it help to you. below code is grab from b2BuoyancyController and it works in my case.

    private function float():void {
        if (bodies.length < 1)
        var body:b2Body = bodies[0];
        if(body.IsAwake() == false){
            //Buoyancy force is just a function of position,
            //so unlike most forces, it is safe to ignore sleeping bodes
        var normal:b2Vec2 = new b2Vec2(0, -1);
        var offset:Number = 20;
        var density:Number = 2;
        var velocity:b2Vec2 = new b2Vec2(0, 0);
        var linearDrag:Number = 2;
        var angularDrag:Number = 1;
        var gravity:b2Vec2 = toolkit.world.GetGravity().Copy();
        var areac:b2Vec2 = new b2Vec2();
        var massc:b2Vec2 = new b2Vec2();
        var area:Number = 0.0;
        var mass:Number = 0.0;
        for(var fixture:b2Fixture=body.GetFixtureList();fixture;fixture=fixture.GetNext()){
            var sc:b2Vec2 = new b2Vec2();
            var sarea:Number = fixture.GetShape().ComputeSubmergedArea(normal, offset, body.GetTransform(), sc);
            area += sarea;
            areac.x += sarea * sc.x;
            areac.y += sarea * sc.y;
            var shapeDensity:Number = 1;
            mass += sarea*shapeDensity;
            massc.x += sarea * sc.x * shapeDensity;
            massc.y += sarea * sc.y * shapeDensity;
        var buoyancyForce:b2Vec2 = gravity.GetNegative();
        //Linear drag
        var dragForce:b2Vec2 = body.GetLinearVelocityFromWorldPoint(areac);
        body.ApplyForce(dragForce, areac);

        if(candy.bodies.length>0){ //TODO 你妹!!!!!
            var tmpForce:b2Vec2 = candy.bodies[0].GetLinearVelocity();
            //tmpForce.x = 0;
            body.ApplyForce(tmpForce, areac);
        //Angular drag
        //TODO: Something that makes more physical sense?

tips:use force instated of impulse and changing linear velocity.


There is a limit in box2D configuration file, but the main problem is with how you implemented bubble. The rope length should always be a less than a value, meaning it shouldn't become longer to give that big reaction in the first place.

  • \$\begingroup\$ thanks for your answer! I have to clarify my question, I just use normal b2body ,and set it's linear Velocity to a fixed value in main loop \$\endgroup\$ – ifree May 25 '12 at 9:17
  • \$\begingroup\$ @ifree try using addforce instead of directly setting velocity. \$\endgroup\$ – Ali1S232 May 25 '12 at 9:25
  • \$\begingroup\$ still not work,and when add force It moves weird \$\endgroup\$ – ifree May 25 '12 at 9:35
  • \$\begingroup\$ In each time step I called b2d.clearForces(),if I don't clear forces i think there would be something strange \$\endgroup\$ – ifree May 25 '12 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.