Problem when using Box 2D Js to handle collision

Hi everybody,
I've developed a simple game like Wind Runner
I'm using Box 2D JS with Cocos 2D HTML5
I attached each ground with the Box2D body

Code: Select all

var b2BodyDef = Box2D.Dynamics.b2BodyDef;
var b2Body = Box2D.Dynamics.b2Body;

var bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_staticBody;

// Add sprite
       var sprite = cc.Sprite.createWithSpriteFrameName(ground.name + ".png");
       sprite.setPosition(cc.p(pos.x + ground.x, pos.y + ground.y));
       sprite.setAnchorPoint(cc.p(0, 0));
       s_GameLayer.addChild(sprite, -1, TAG_GROUND);

//add body
       bodyDef.position.Set(posX + ground.x / PTM_RATIO, posY + ground.y / PTM_RATIO);
       bodyDef.userData = sprite;
       var b2ground = s_b2World.CreateBody(bodyDef);
       this._GB2ShapeCache.addFixturesToBody(b2ground, ground.name);
      sprite.setUserData(b2ground);

And when create the running man i attached with the Box 2D body, too

Code: Select all

       var b2BodyDef = Box2D.Dynamics.b2BodyDef,
            b2Body = Box2D.Dynamics.b2Body,
            b2Vec2 = Box2D.Common.Math.b2Vec2;

        var bodyDef = new b2BodyDef();
        bodyDef.type = b2Body.b2_dynamicBody;
        bodyDef.position.Set(pos.x / PTM_RATIO, pos.y / PTM_RATIO);
        bodyDef.userData = this;
        this.body = s_b2World.CreateBody(bodyDef);
        this.body.SetFixedRotation(true);

        cc.GB2ShapeCache.getInstance().addFixturesToBody(this.body, "character_run_2");

        this.body.SetLinearVelocity(new b2Vec2(this.speed, 0));

Then i load multple grounds like this attached image
https://dl.dropboxusercontent.com/u/63045417/Images/Screen%20Shot%202013-07-24%20at%205.38.01%20PM.png
My problem is sometimes when the running man collided with ground, it had a weird behavior. it collided with the line between each ground and went back unfortunately
Can everybody help me?Any help would be greatly appreciated
Sorry for my bad English
viewtopic.php?f=8&t=3292
viewtopic.php?f=8&t=7917
viewtopic.php?f=20&t=9359
Tks 4 your reply,irresistible force 🙄 🙂

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