hello, can anybody help me with this?
in my top-down viewed game (no gravity) I have function, that creates a chain of 2 - 10 bullet bodies (little boxes, count according to variable "count") connected using revolute joint and throws them against the wall (static body, zero restitution):
works good for me, but sometimes after collision with wall, there are one or two bodies in chain, that did not fall to sleep, but they are still jerking or shaking and very slowly moving around
what is the problem? What am I doing wrong or how can I correct this? Or am I reaching Box2D limits?
thanks
in my top-down viewed game (no gravity) I have function, that creates a chain of 2 - 10 bullet bodies (little boxes, count according to variable "count") connected using revolute joint and throws them against the wall (static body, zero restitution):
Code:
public function throwChain(count:int):void{
var i:int;
var anchor:b2Vec2 = new b2Vec2();
var body:b2Body;
{
var sd:b2PolygonDef = new b2PolygonDef();
sd.SetAsBox(6/m_physScale, 3.5/m_physScale);
sd.density = 2;
sd.friction = 0.5;
sd.restitution = 0.1;
var bd:b2BodyDef = new b2BodyDef();
var smerY:Number = genCislo(0,5)-2.5;
var color:Number = Math.round(genCislo(1,5));
bd.angularDamping = 3;
bd.linearDamping = genCislo(2.0,2.3);
bd.isBullet = true;
bd.position.Set(dlanPos.x/m_physScale, dlanPos.y/m_physScale);
bd.userData = new Cecko();
bd.userData.gotoAndStop(color);
bd.userData.rotation = 90;
bd.userData.hrac = new Number(whoPlays);
bd.userData.ret = new Number(count);
body = m_world.CreateBody(bd);
body.CreateShape(sd);
body.SetMassFromShapes();
sim_kont.addChild(bd.userData);
body.ApplyImpulse(new b2Vec2(fireTo.x*silaHodu, fireTo.y*silaHodu),body.GetWorldCenter());
body.ApplyTorque(genCislo(0.1,0.4)-0.15);
var jd:b2RevoluteJointDef = new b2RevoluteJointDef();
jd.lowerAngle = -120/(180/Math.PI);
jd.upperAngle = +120/(180/Math.PI);
jd.enableLimit = true;
var prevBody:b2Body = body;
for (i = 0; i < count-1; ++i)
{
color = Math.round(genCislo(1,5));
bd.position.Set((dlanPos.x + 8 + 8 * i)/m_physScale, dlanPos.y/m_physScale);
bd.userData = new Cecko();
bd.userData.hrac = new Number(whoPlays);
bd.userData.ret = new Number(count);
bd.userData.gotoAndStop(color);
bd.userData.rotation = 90;
body = m_world.CreateBody(bd);
body.CreateShape(sd);
body.SetMassFromShapes();
sim_kont.addChild(bd.userData);
anchor.Set((dlanPos.x + 4 + 8 * i)/m_physScale, dlanPos.y/m_physScale);
jd.Initialize(prevBody, body, anchor);
m_world.CreateJoint(jd);
if(i==1 || i==3 || i==5 || i==7 || i==9){
body.ApplyImpulse(new b2Vec2(fireTo.x*throwPover, fireTo.y*throwPower), body.GetWorldCenter());
}
prevBody = body;
}
}
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
inGame = true;
}
var i:int;
var anchor:b2Vec2 = new b2Vec2();
var body:b2Body;
{
var sd:b2PolygonDef = new b2PolygonDef();
sd.SetAsBox(6/m_physScale, 3.5/m_physScale);
sd.density = 2;
sd.friction = 0.5;
sd.restitution = 0.1;
var bd:b2BodyDef = new b2BodyDef();
var smerY:Number = genCislo(0,5)-2.5;
var color:Number = Math.round(genCislo(1,5));
bd.angularDamping = 3;
bd.linearDamping = genCislo(2.0,2.3);
bd.isBullet = true;
bd.position.Set(dlanPos.x/m_physScale, dlanPos.y/m_physScale);
bd.userData = new Cecko();
bd.userData.gotoAndStop(color);
bd.userData.rotation = 90;
bd.userData.hrac = new Number(whoPlays);
bd.userData.ret = new Number(count);
body = m_world.CreateBody(bd);
body.CreateShape(sd);
body.SetMassFromShapes();
sim_kont.addChild(bd.userData);
body.ApplyImpulse(new b2Vec2(fireTo.x*silaHodu, fireTo.y*silaHodu),body.GetWorldCenter());
body.ApplyTorque(genCislo(0.1,0.4)-0.15);
var jd:b2RevoluteJointDef = new b2RevoluteJointDef();
jd.lowerAngle = -120/(180/Math.PI);
jd.upperAngle = +120/(180/Math.PI);
jd.enableLimit = true;
var prevBody:b2Body = body;
for (i = 0; i < count-1; ++i)
{
color = Math.round(genCislo(1,5));
bd.position.Set((dlanPos.x + 8 + 8 * i)/m_physScale, dlanPos.y/m_physScale);
bd.userData = new Cecko();
bd.userData.hrac = new Number(whoPlays);
bd.userData.ret = new Number(count);
bd.userData.gotoAndStop(color);
bd.userData.rotation = 90;
body = m_world.CreateBody(bd);
body.CreateShape(sd);
body.SetMassFromShapes();
sim_kont.addChild(bd.userData);
anchor.Set((dlanPos.x + 4 + 8 * i)/m_physScale, dlanPos.y/m_physScale);
jd.Initialize(prevBody, body, anchor);
m_world.CreateJoint(jd);
if(i==1 || i==3 || i==5 || i==7 || i==9){
body.ApplyImpulse(new b2Vec2(fireTo.x*throwPover, fireTo.y*throwPower), body.GetWorldCenter());
}
prevBody = body;
}
}
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
inGame = true;
}
works good for me, but sometimes after collision with wall, there are one or two bodies in chain, that did not fall to sleep, but they are still jerking or shaking and very slowly moving around
what is the problem? What am I doing wrong or how can I correct this? Or am I reaching Box2D limits?
thanks