Beginner Question: Falling objects

Hello,

so far I did this: http://tinyurl.com/38du6qe when trying to create a falling create
following the beginner tutorials @ http://www.kerp.net.

What do I have to do to make the creat fall, here is my code:

Code:

package  {
   
   import Box2D.Collision.b2AABB;
   import Box2D.Collision.b2Bound;
   import Box2D.Collision.Shapes.b2PolygonDef;
   import Box2D.Common.Math.b2Vec2;
   import Box2D.Dynamics.b2Body;
   import Box2D.Dynamics.b2BodyDef;
   import Box2D.Dynamics.b2DebugDraw;
   import Box2D.Dynamics.b2World;
   import flash.display.MovieClip;
   import flash.display.Sprite;
   import flash.events.Event;
   
   /**
    * ...
    * @author mirzahat
    */
   public class HelloBox extends MovieClip
   {
      
      protected var _world:b2World;
      
      protected const RATIO:Number = 30;
      protected var _fallingCreate:b2Body;
      
      public function HelloBox() {
         
         setupWorld();
         
         createWallsAndFloor();
         
         addACreate();
         
         setupDraw();
         
         addEventListener(Event.ENTER_FRAME, frameEntered);
         
      }
      
      protected function addACreate():void {
      
         var fallingCreateDef:b2PolygonDef = new b2PolygonDef();
         fallingCreateDef.SetAsBox(25 / RATIO, 25 / RATIO);
         
         fallingCreateDef.friction = 0.8;
         fallingCreateDef.restitution = 0.3;
         fallingCreateDef.density = 0.7;
         
         var fallingBodyDef:b2BodyDef = new b2BodyDef();
         fallingBodyDef.position.Set(250 / RATIO, -30 / RATIO);
         fallingBodyDef.angle = 30 * Math.PI / 180;
         
         _fallingCreate = _world.CreateBody(fallingBodyDef);
         _fallingCreate.CreateShape(fallingCreateDef);
         _fallingCreate.SetMassFromShapes();
         
      }
      
      protected function frameEntered(e:Event):void {
         
         _world.Step(1.0 / 30, 10);
         
         trace("pada x: " + _fallingCreate.GetPosition().x + ", pada y: " + _fallingCreate.GetPosition().y);
         
      }
      
      protected function setupWorld() {
         
         //set up the size of the universe
         var universeSize:b2AABB = new b2AABB();
         universeSize.lowerBound.Set(-3000 / RATIO, 3000 / RATIO);
         universeSize.upperBound.Set( -3000 / RATIO, 3000 / RATIO);
         
         //define gravity
         var gravity:b2Vec2 = new b2Vec2(0, 9.8);
         
         //ignore sleeping object
         var ignoreSleeping:Boolean = true;
         
         _world = new b2World(universeSize, gravity, ignoreSleeping);
      
         //trace("My world has: " + _world.GetBodyCount());
         
         
      }
      
      protected function setupDraw():void {
      
         var spriteToDrawOn:Sprite = new Sprite();
         this.addChild(spriteToDrawOn);
         
         var artistForHire:b2DebugDraw = new b2DebugDraw();
         artistForHire.m_sprite = spriteToDrawOn;
         artistForHire.m_drawScale = RATIO;
         artistForHire.SetFlags(b2DebugDraw.e_shapeBit);
         artistForHire.m_lineThickness = 2.0;
         artistForHire.m_fillAlpha = 0.6;
         
         _world.SetDebugDraw(artistForHire);
         
      }
      
      protected function createWallsAndFloor() {
      
         //create the shape, polygon definition
         var bigLongShapeDef:b2PolygonDef = new b2PolygonDef();
         bigLongShapeDef.vertexCount = 4;
         b2Vec2(bigLongShapeDef.vertices[0]).Set(0 / RATIO, 0 / RATIO);
         b2Vec2(bigLongShapeDef.vertices[1]).Set(550 / RATIO, 0 / RATIO);
         b2Vec2(bigLongShapeDef.vertices[2]).Set(550 / RATIO, 10 / RATIO);
         b2Vec2(bigLongShapeDef.vertices[3]).Set(0 / RATIO, 10 / RATIO);
         
         bigLongShapeDef.friction = 0.5;
         bigLongShapeDef.restitution = 0.3;
         bigLongShapeDef.density = 0.0;
         
         //create the body definition
         var floorBodyDef:b2BodyDef = new b2BodyDef();
         floorBodyDef.position.Set(0 / RATIO, (400 / RATIO) - (10 / RATIO));
         
         //create the body
         var floorBody:b2Body = _world.CreateBody(floorBodyDef);
         
         //create the shape
         floorBody.CreateShape(bigLongShapeDef);
         floorBody.SetMassFromShapes();
         
         //trace("My world has " + _world.m_bodyCount);
         
         var tallSkinnyShapeDef:b2PolygonDef = new b2PolygonDef();
         tallSkinnyShapeDef.SetAsBox(5 / RATIO, 195 / RATIO);
         tallSkinnyShapeDef.friction = 0.5;
         tallSkinnyShapeDef.restitution = 0.3;
         tallSkinnyShapeDef.density = 0.0;
         
         var wallBodyDef:b2BodyDef = new b2BodyDef();
         wallBodyDef.position.Set(5 / RATIO, 195 / RATIO);
         
         var leftWall:b2Body = _world.CreateBody(wallBodyDef);
         leftWall.CreateShape(tallSkinnyShapeDef);
         leftWall.SetMassFromShapes();
         
         wallBodyDef.position.Set(545 / RATIO, 195 / RATIO);
         var rightWall:b2Body = _world.CreateBody(wallBodyDef);
         rightWall.CreateShape(tallSkinnyShapeDef);
         rightWall.SetMassFromShapes();
         
      }
      
   }

}




Regards,
Mirza
is your trace returning changing values?
Quote:
trace("pada x: " + _fallingCreate.GetPosition().x + ", pada y: " + _fallingCreate.GetPosition().y);
no...that's my goal
i think you need to set your crate to dynamic, (it might default as static)
and how is that done?
Hello

When an object is outside the world bounds, it automatically becomes static.

You made a small error when setting up your world, causing your box to become static.

Code:
//Wrong
universeSize.lowerBound.Set(-3000 / RATIO, 3000 / RATIO);
universeSize.upperBound.Set( -3000 / RATIO, 3000 / RATIO);

//Correct
universeSize.lowerBound.Set(-3000 / RATIO, -3000 / RATIO);
universeSize.upperBound.Set( 3000 / RATIO, 3000 / RATIO);


Simon

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