I can't setup the Buoyancy

Hey,

I checked the testbed in order to setup a buoyancy effect.
I thought the next 4 lines were all that I need:
Code:
var be:b2BuoyancyEffect = new b2BuoyancyEffect();
be.density = 1.5;
be.offset = -300 / Constants.RATIO;
var c:b2Controller = new b2Controller(Constants._myWorld, be, true);

but nevertheless I cannot make it work in my class.

The full code:
Code:
package
{
   import Box2DAS.Dynamics.Joints.b2RevoluteJoint;
   import Box2DAS.Dynamics.Joints.b2RevoluteJointDef;
   import Box2DAS.Dynamics.Joints.b2JointDef;
   import Box2DAS.Controllers.b2Controller;
   import Box2DAS.Controllers.b2BuoyancyEffect;
   import Box2DAS.Dynamics.b2DebugDraw;
   import Box2DAS.Collision.Shapes.b2PolygonShape;
   import Box2DAS.Dynamics.b2Body;
   import Box2DAS.Common.b2Def;
   import Box2DAS.Dynamics.b2World;
   import Physics.Constants;
   import Box2DAS.Common.V2;
   import flash.events.Event;
   import flash.display.Sprite;

   public class Anwsi extends Sprite
   {
      private var  swma:b2Body;
      private var  swma2:b2Body;
      public var debug:b2DebugDraw;
      private var k:b2RevoluteJoint;
      public function  Anwsi()
      {
         setupWorld();
         
         createBody();
         
         createPhysicsDebug();
         
         activateAnwsi();
         
         addEventListener(Event.ENTER_FRAME, goWorld);
      }

      private function createPhysicsDebug() : void
      {
         debug = new b2DebugDraw();
         addChild(debug);
      }

      private function setupWorld() : void
      {
         var gravity:V2 = new V2(0.0,9.0);
         var doSleep:Boolean = true;
         
         Constants._myWorld=new b2World(gravity,doSleep);
         
      }

      private function createBody() : void
      {

         
         b2Def.body.type = b2Body.b2_dynamicBody;
         b2Def.fixture.shape = new b2PolygonShape();
         b2PolygonShape(b2Def.fixture.shape).SetAsBox(50 / Constants.RATIO, 50 / Constants.RATIO);
         b2Def.fixture.density = 1;
         swma2 = Constants._myWorld.CreateBody(b2Def.body);
         swma2.CreateFixture(b2Def.fixture);
         
         swma2.SetTransform(new V2(300/30, 250/30), 0);
         
         
         
      }

      private function activateAnwsi() : void
      {
         var be:b2BuoyancyEffect = new b2BuoyancyEffect();
         be.density = 1.5;
         be.offset = -300 / Constants.RATIO;
         var c:b2Controller = new b2Controller(Constants._myWorld, be, true);
      }

      private function goWorld(event : Event) : void
      {
         Constants._myWorld.Step(1/60, 10,10);
         Constants._myWorld.ClearForces();
         
         debug.graphics.clear();
         debug.world = Constants._myWorld;
         debug.scale = Constants.RATIO;
         debug.Draw();
         
      }
   }
}


What am I missing? 😳
That looks right. Are you sure the offset for buoyancy is such that it will actually effect something on the stage?

You could try flipping the buoyancy normal:

Code:
be.normal.y = 1;


As a quick test to see if it is having any effect at all.
I used some trace commands within b2BuoyancyEffect class and it seems that it accesses normally my body in every frame in which it is within the buoyancy area. But the forces don't affect it at all :O I put there setlinearvelocity and it affects my body normally. Nevertheless no matter how much applyforce I put, it doesn't affect it at all...
Hmm... I think you're going to have to post a test project for us to get anywhere.

Original thread: https://box2d.org/forum/viewtopic.php?t=6149