簡體   English   中英

Box2d As3的棱鏡關節不起作用?

[英]Prismatic Joints for Box2d As3 won't work?

我正在嘗試使用棱柱形關節在box2d中創建一個移動平台,所創建的只是一個盒子並且沒有明顯的關節,我在做什么錯? 這是我的代碼

        var prismaticJoint:b2PrismaticJoint;
        ...
        {
         ...
        BodyDef.position.Set(0 / RATIO, 0 / RATIO);
        floorDef.SetAsBox(250 / RATIO, 10 / RATIO);

        fixtureDef.shape = floorDef;
        fixtureDef.friction = 0.5;
        fixtureDef.density = 0.5;
        fixtureDef.restitution = 0;

        movePlatformBody = PhysiVals.world.CreateBody(BodyDef);
        movePlatformBody.CreateFixture(fixtureDef);


        var prismaticJointDef:b2PrismaticJointDef = new b2PrismaticJointDef();
        prismaticJointDef.Initialize(body, movePlatformBody, movePlatformBody.GetWorldCenter(), new b2Vec2(0,1));
        prismaticJointDef.enableLimit = true;
        prismaticJointDef.enableMotor = true;
        prismaticJointDef.lowerTranslation = 0;
        prismaticJointDef.maxMotorForce = 100;
        prismaticJointDef.motorSpeed = 1;
        prismaticJointDef.upperTranslation = 270 / PhysiVals.RATIO;
        PhysiVals.world.CreateJoint(prismaticJointDef);
        //prismaticJoint = PhysiVals.world.CreateJoint(prismaticJointDef as b2JointDef) as b2PrismaticJoint;

我嘗試了兩種在世界上創建它的方法,但我不知道該使用哪種方法。 如何在box2d中創建移動平台? 感謝您抽出時間來閱讀。

嘗試修改您的Initialize語句。 將第一個參數設置為要移動的物體(平台),將第二個參數設置為靜態物體(世界),第三個參數將為平台的中心。

我編寫了一個非常流行的Box2D關節教程,並提供了帶有源代碼的Prismatic Joints示例,因此如果您仍然遇到問題Tutorial ,也可以看看。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM