Hi everyone,
I am making my first box2d flash as3 game just like pong, but have faced a very weird problem,
first of all I create walls left right top and bottom
Code:
function CreateBound(){
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(0 / m_physScale, 0 / m_physScale);
//left
var leftSide:b2PolygonShape = new b2PolygonShape();
leftSide.SetAsEdge(new b2Vec2(0, 0/ m_physScale),new b2Vec2(0/ m_physScale, 320 / m_physScale));
var leftFixt:b2FixtureDef = new b2FixtureDef();
leftFixt.shape = leftSide;
//right
var rightSide:b2PolygonShape = new b2PolygonShape();
rightSide.SetAsEdge(new b2Vec2(480/ m_physScale, 0/ m_physScale),new b2Vec2(480/ m_physScale, 320 / m_physScale));
var rightFixt:b2FixtureDef = new b2FixtureDef();
rightFixt.shape = rightSide;
//top
var topSide:b2PolygonShape = new b2PolygonShape();
topSide.SetAsEdge(new b2Vec2(0/ m_physScale, 0/ m_physScale),new b2Vec2(480/ m_physScale, 0 / m_physScale));
var topFixt:b2FixtureDef = new b2FixtureDef();
topFixt.shape = topSide;
//bottom
var bottomSide:b2PolygonShape = new b2PolygonShape();
bottomSide.SetAsEdge(new b2Vec2(0/ m_physScale, 320/ m_physScale),new b2Vec2(480/ m_physScale, 320 / m_physScale));
var bottomFixt:b2FixtureDef = new b2FixtureDef();
bottomFixt.shape = bottomSide;
var world_body:b2Body = world.CreateBody(bodyDef);
world_body.CreateFixture(leftFixt);
world_body.CreateFixture(rightFixt);
world_body.CreateFixture(topFixt);
world_body.CreateFixture(bottomFixt);
}
then create the 'ball'
Code:
var bodyDef2:b2BodyDef = new b2BodyDef();
bodyDef2.position.Set(249 / m_physScale, 100 / m_physScale);
bodyDef2.type = b2Body.b2_dynamicBody;
bodyDef2.linearVelocity.Set(50,50);
bodyDef2.inertiaScale = 2;
//bodyDef2.angularVelocity = 1;
body = world.CreateBody(bodyDef2);
var fd:b2FixtureDef = new b2FixtureDef();
fd.shape = mycircle;
fd.restitution = 1;
fd.density = 1;
body.CreateFixture(fd);
everything works fine in the beginning....after the 'ball' rebounds a few times with the 'walls', the 'ball' keep rebounding with the top and bottom 'wall' and collision and same point everytime, that's mean the 'ball' keep moving in the same track, up and down, up and down, and never move the collide left/ right wall again........What 's the problem??
Thanks for any kindly help!!