Bird's Eye Physics

I am making a golf game but can get the ball to slow down after I hit it.

Gravity is set to 0,0
and the ball has a friction = 0
linearDamping = 1;
angularDamping = 1;

But it still never slows down. Any help?
damping isnt measured from 0-1. So try a higher value, like 10
I have tried values larger than 1, 10, 100, 100000000 still no go?

I am applying it to the ball, is that incorrect?
Post your code for creating the body and shape
I actually figured it out, just had to declare the damping out of the function that created my shapes.

New problem/question however, is there a way to dynamically change the damping, so for example a ball passes over sand I want it to slow down quickly. Here is my code all the same 🙂

Note I took alot of the creation code for the world from http://www.emanueleferonato.com/2009/01 ... beginners/


Code:
var bDef:b2BodyDef = new b2BodyDef();
   bDef.linearDamping = .2;
   bDef.angularDamping = .4;

   import Box2D.Dynamics.*;
   import Box2D.Collision.*;
   import Box2D.Collision.Shapes.*;
   import Box2D.Common.Math.*;
   var mouseDowned = false;
   var power=0;
   var body:b2Body;
       var the_world:b2World;
      var time_count:Timer=new Timer(1000);
       var ar = new arrow();
          ar.x = 800;
          ar.y = 800;
          addChild(ar);
       function demo() {
         
         var environment:b2AABB = new b2AABB();
         environment.lowerBound.Set(-100.0, -100.0);
         environment.upperBound.Set(100.0, 100.0);
         var gravity:b2Vec2=new b2Vec2(0,0);
         the_world=new b2World(environment,gravity,true);
         var debug_draw:b2DebugDraw = new b2DebugDraw();
         var debug_sprite:Sprite = new Sprite();
         addChild(debug_sprite);
         debug_draw.m_sprite=debug_sprite;
         debug_draw.m_drawScale=30;
         debug_draw.m_fillAlpha=1;
         debug_draw.m_lineThickness=1;
         debug_draw.m_drawFlags=b2DebugDraw.e_shapeBit;
         the_world.SetDebugDraw(debug_draw);
         
         
         sampleLevel();
         
         placeBall(357,647);
         
         
         addEventListener(Event.ENTER_FRAME, on_enter_frame);
      
         time_count.start();
         
         
      }
      
      
      
   
demo();

function on_enter_frame(e:Event) {
   
         the_world.Step(1/30, 30);
         
         
         
         
         
         
         
      }
      
      
      //creates the board...
         function sampleLevel(){
            var final_body:b2Body;
         var the_body:b2BodyDef;
         var the_box:b2PolygonDef;
         the_body = new b2BodyDef();
         the_body.position.Set(357/30, 678/30);
         the_box = new b2PolygonDef();
         the_box.SetAsBox(220/60, 16./60);
         the_box.friction=0;
         the_box.density=0;
         final_body=the_world.CreateBody(the_body);
         final_body.CreateShape(the_box);
         //final_body.SetMassFromShapes();
         
         
         
         
         the_body.position.Set(357/30, 32/30);
         the_box = new b2PolygonDef();
         the_box.SetAsBox(220/60, 16./60);
         the_box.friction=0;
         the_box.density=0;
         final_body=the_world.CreateBody(the_body);
         final_body.CreateShape(the_box);
         
         the_body.position.Set(253/30, 348/30);
         the_box = new b2PolygonDef();
         the_box.SetAsBox(16/60, 650./60);
         the_box.friction=0;
         the_box.density=0;
         final_body=the_world.CreateBody(the_body);
         final_body.CreateShape(the_box);
         
         the_body.position.Set(460/30, 348/30);
         the_box = new b2PolygonDef();
         the_box.SetAsBox(16/60, 650/60);
         the_box.friction=0;
         the_box.density=0;
         final_body=the_world.CreateBody(the_body);
         final_body.CreateShape(the_box);
         
         the_body.linearDamping = 10;
         }
   
//creates my ball...      
function placeBall(theX, theY){

         bDef.position.Set(theX/30,theY/30);
         var circleDef = new b2CircleDef();
         


         circleDef.radius= 15/60;
         circleDef.density = 10;
         circleDef.friction = .00;
         circleDef.restitution = 1;
         body = the_world.CreateBody(bDef);
         body.CreateShape(circleDef);
         body.SetMassFromShapes();   
         bDef.isBullet = true;
         

//circleDef.WakeUp();
 

}



stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDowned);
function keyDowned(e:KeyboardEvent){
    if(e.keyCode==32){
       trace(bDef.linearDamping);
       bDef.linearDamping*=1.25;
    }
}
you could try setting body.m_linearDamping. Not sure if it will work as expected though as this is really a private property. (i think)
This seems to work perfectly, just put it in an event that reoccurs every frame.

Code:
var scale = .99;
var dirThing:b2Vec2 = body.GetLinearVelocity();
dirThing.x *=scale;
dirThing.y *=scale;
body.SetLinearVelocity(dirThing);


if I change scale to a smaller number it makes the "friction" greater.

😁
You are now coding your own physics to simulate friction which kind of defeats the point of using a physics engine. But yes, it probably works!

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