学习 Box2D 个人笔记(六)PrismaticJoint

从这篇开始,我开始学习关于  joint。


首先,咱们要先了解PrismaticJoint。

如果你想要做一个活塞运动的效果,那么就可以用这个,这个关节的作用就是限制物体在某一个方向上运动。

    b2PrismaticJointDef PrismaticJointDef; 
    b2Vec2 worldAxis(0,-1);
    PrismaticJointDef.collideConnected =true;
    PrismaticJointDef.Initialize(spriteBody, groundBody, spriteBody->GetWorldCenter(), worldAxis);    //第一个参数指运动的物体,第二个参数指相对的物体,第三个参数指平移的锚点,第四个是限制的方向
    world->CreateJoint(&PrismaticJointDef);
    

这样就限制了物体spriteBody在GroundBody上上下运动。


你可能感兴趣的:(学习 Box2D 个人笔记(六)PrismaticJoint)