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;
}
}