翻转后,Dynamic Body卡在静止的身体中

时间:2014-12-09 12:01:51

标签: c++ box2d game-physics

我有一个动态的身体,有许多多边形形状供我的游戏角色使用。为了转回游戏角色,我使用以下代码翻转顶点:

void Box2dManager::flipFixtures(bool horizzontally, b2Body* physBody)
{
    b2Fixture* fix = physBody->GetFixtureList();

    while(fix)
    {
        b2Shape* shape = fix->GetShape();
        if(shape->GetType()== b2Shape::e_polygon)
        {   
            // flipping x or y coordinates
            b2PolygonShape* ps = (b2PolygonShape*)shape;
            for(int i=0; i < ps->GetVertexCount(); i++)
                horizzontally ? ps->m_vertices[i].x *= -1 : ps->m_vertices[i].y *= -1;

            // revert the vertices (no need after Box2D 2.3.0 as polygon creation computes the convex hull)
            b2Vec2* reVert = new b2Vec2[ps->GetVertexCount()];
            int j = ps->GetVertexCount() -1;
            for(int i=0; i<ps->GetVertexCount();i++)
                reVert[i] = ps->m_vertices[j--];

            ps->Set(&reVert[0], ps->GetVertexCount());
        }
        fix = fix->GetNext();
    }
}

我也有静态边缘形状作为墙壁。碰巧的是,当我翻转角色时,有时相同多边形的顶点似乎位于相同静态边缘形状的不同边。结果我的角色贴在墙上(它被困在静态边缘形状)。我应该如何处理这种情况?

0 个答案:

没有答案