different weights with objects?

I'm probably missing something really simple


you'll see in the code below i have

playerBox.density = 20;
playerBox.friction = 10;// 0.4;
playerBox.restitution = 0.09;

I have tried making density friction and resitution all kinds of values but it doesn't seem to change anything.

I want to be able to have 2 objects, one being maybe a feather, and another being a brick. obviously the feather will fall much slower due to wind resistance and weight, vs a brick slamming to the ground.


I am only using single blocks that do NOT rotate, im trying to develop of fighter game so feet (bottom of square) must always be facing ground


If you can give me any advice on how to achieve different weights I would greatly appreciate it! There are heavier characters and lighter characters, also if a lighter character gets hit they will fly further because they weigh less.

also I want to be able to have different punch powers, which will change what velocity the player being hit flies, etc


here is my class

Code:
package
{
   import Box2D.Dynamics.*;
   import Box2D.Collision.*;
   import Box2D.Collision.Shapes.*;
   import Box2D.Dynamics.Joints.*;
   import Box2D.Dynamics.Contacts.*;
   import Box2D.Common.*;
   import Box2D.Common.Math.*;
   import flash.display.DisplayObjectContainer;
   import flash.display.MovieClip;
   import flash.display.Sprite;
   import flash.display.Stage;
   import flash.events.Event;
   import flash.events.MouseEvent;
   
   public class TestLevel extends Sprite
   {
      private var _world:b2World;
      private var _debugSprite:Sprite;
      
      private var _realGameSprite:Sprite
      
      //testing
      public var m_iterations:int = 1;
      public var m_timeStep:Number = 1 / 30;
      
      private var _playersArray:Array;
      
      public function TestLevel()
      {
         addEventListener(Event.ADDED_TO_STAGE, init);
      }
      
      public function init(event:Event):void
      {
         removeEventListener(Event.ADDED_TO_STAGE, init);
         
         var worldAABB:b2AABB = new b2AABB();
         worldAABB.lowerBound.Set(-1000.0, -1000.0);
         worldAABB.upperBound.Set(1000.0, 1000.0);
         
         //x / y gravity
         var gravity:b2Vec2 = new b2Vec2(0, 100.0);
         var doSleep:Boolean = true;
         
         _world = new b2World(worldAABB, gravity, doSleep);
         
         //setup debug stuff
         _debugSprite = new Sprite();
         
         var dbgDraw:b2DebugDraw = new b2DebugDraw();
         dbgDraw.m_sprite = _debugSprite;
         dbgDraw.m_drawScale = 1;
         dbgDraw.m_fillAlpha = 0.2;
         dbgDraw.m_lineThickness = 0;// 1.0;
         dbgDraw.m_drawFlags = b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit;
         _world.SetDebugDraw(dbgDraw);
         
         // Create border of boxes
         var wallSd:b2PolygonDef = new b2PolygonDef();
         var wallBd:b2BodyDef = new b2BodyDef();
         var wallB:b2Body;
         
         // Left
         wallBd.position.Set(60, 300);
         wallSd.SetAsBox(40, 90);
         wallB = _world.CreateBody(wallBd);
         wallB.CreateShape(wallSd);
         wallB.SetMassFromShapes();
         
         // Bottom
         wallBd.position.Set(640 / 2, (360 + 95));
         wallSd.SetAsBox(680/2, 100);
         wallBd.angle = 91;
         wallB = _world.CreateBody(wallBd);
         wallB.CreateShape(wallSd);
         wallB.SetMassFromShapes();
         
         var playerBodyDef:b2BodyDef;
         var playerBox:b2PolygonDef;
         
         _playersArray = new Array();
         
         // create players
         var i:int;
         for (i = 0; i < 6; i++)
         {
            var startX:Number = 70 + (i * 100);// 70 + Math.random() * 20 + 480 * i;
            var startY:Number = 20;// 100 * i;
            
            playerBox = new b2PolygonDef();
            
            // player
            if (i % 2 == 0)
            {
               playerBox.SetAsBox(50, 53);
            }
            else
            {
               playerBox.SetAsBox(32, 38);
            }
            playerBox.density = 20;
            playerBox.friction = 10;// 0.4;
            playerBox.restitution = 0.09;
            
            playerBodyDef = new b2BodyDef();
            playerBodyDef.fixedRotation = true;
            playerBodyDef.position.Set(startX, (startY + 28));
            
            var player:b2Body = _world.CreateBody(playerBodyDef);
            player.CreateShape(playerBox);
            player.SetMassFromShapes();
            
            _playersArray.push(player);
         }
         
         addChild(new LevelGraphix());
         _realGameSprite = new Sprite();
         addChild(_realGameSprite);
         _debugSprite.alpha = .7;
         addChild(_debugSprite);
         
         //create real world objects
         for (i = 0; i < _playersArray.length; i++)
         {
            var playerObject:b2Body = _playersArray[i] as b2Body;
            var pos:b2Vec2 = playerObject.GetPosition();
            
            var obj:MovieClip = (i % 2) ? new PlayerBlob() : new PlayerBear();
            obj.x = pos.x;
            obj.y = pos.y;
            
            _realGameSprite.addChild(obj);
         }
         
         //_oef(new Event(Event.ENTER_FRAME));
         addEventListener(Event.ENTER_FRAME, _oef);
         stage.addEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove);
         stage.addEventListener(MouseEvent.CLICK, _onStageClick);
      }
      
      private function _onMouseMove(event:MouseEvent):void
      {
         _debugSprite.alpha = stage.mouseX / 500;
      }
      
      private function _onStageClick(event:MouseEvent):void
      {
         return;
      }
      
      
      private function _oef(event:Event):void
      {
         _world.Step(m_timeStep, m_iterations);
         
         //position real world objects
         var i:int;
         for (i = 0; i < _playersArray.length; i++)
         {
            var obj:Sprite = _realGameSprite.getChildAt(i) as Sprite;
            var playerObject:b2Body = _playersArray[i] as b2Body;
            var pos:b2Vec2 = playerObject.GetPosition();
            obj.x = pos.x;
            obj.y = pos.y + playerObject.hy;
         }
      }
   }
}
A feather will fall slower because of air resistance, it has nothing to do with its weight ; the speed of a falling object does not depends on its mass, Newton pointed that out 😛
ahh wow yeah, duh. brings me back to elementary school demo of a air vacuumed tube

okay.... then how do I introduce air resistance into this equation? is there something built in for that in box2d?

also im not sure how to get the right effect, to make it look like the farther an object falls the more speed it gains. maybe there is a maximum speed setting?

any pointers would be greatly appreciated!
I think the most realistic way would be to apply a force to the body in the opposite direction to it's current movement, scaled by how fast it's moving. That should give you a 'terminal velocity' at some point. There is also body->SetLinearDamping(float) which might be useful, I haven't checked exactly what it does though.
thanks that helps, i'm starting to get a hang of this

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