Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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{
         if(this.combined){
            this.getBody().SetLinearVelocity(velocity);//velocity=new b2Vec2(0,-3.5);
         }
     }
     //other code
}
class Main{
    public function loop(){
        getAllPhyObject().forEach(function(phyObj){
              phyobj.draw();
        });
    }

}

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?
thanks!
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.

    //buoyancy
    private function float():void {
        if (bodies.length < 1)
            return;
        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
            return;
        }
        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;
        }
        areac.x/=area;
        areac.y/=area;
        massc.x/=mass;
        massc.y/=mass;
        if(area<Number.MIN_VALUE)
            return;
        //Buoyancy
        var buoyancyForce:b2Vec2 = gravity.GetNegative();
        buoyancyForce.Multiply(density*area)
        body.ApplyForce(buoyancyForce,massc);
        //Linear drag
        var dragForce:b2Vec2 = body.GetLinearVelocityFromWorldPoint(areac);
        dragForce.Subtract(velocity);
        dragForce.Multiply(-linearDrag*area);
        body.ApplyForce(dragForce, areac);

        //tmpForce
        if(candy.bodies.length>0){ //TODO 你妹!!!!!
            var tmpForce:b2Vec2 = candy.bodies[0].GetLinearVelocity();
            body.SetLinearVelocity(tmpForce);
            //tmpForce.x = 0;
            //tmpForce.Subtract(velocity);
            //tmpForce.Multiply(-linearDrag*area);
            body.ApplyForce(tmpForce, areac);
        }
        //Angular drag
        //TODO: Something that makes more physical sense?
        body.ApplyTorque(-body.GetInertia()/body.GetMass()*area*body.GetAngularVelocity()*angularDrag)
    }

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

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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 –  ifree May 25 '12 at 9:17
    
@ifree try using addforce instead of directly setting velocity. –  Ali.S May 25 '12 at 9:25
    
still not work,and when add force It moves weird –  ifree May 25 '12 at 9:35
    
In each time step I called b2d.clearForces(),if I don't clear forces i think there would be something strange –  ifree May 25 '12 at 9:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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