2013-03-20 61 views
0

即時通訊嘗試在box2d中使用棱鏡關節創建移動平臺,所有創建的都是一個盒子,並且沒有明顯的關節,我做錯了什麼?這裏是我的代碼Box2d As3棱鏡接頭不起作用?

 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; 

我試過2種方式在世界上創建它,我不知道使用哪一個。如何在box2d中創建移動平臺?感謝您抽出時間來閱讀。

回答

1

嘗試修改您的初始化語句。將第一個參數設置爲要移動的主體(平臺),將第二個參數設置爲靜態主體(世界),第三個參數爲平臺中心。

我寫了一個關於Box2D關節的非常流行的教程,其中帶有源代碼的棱鏡關節的示例,因此如果您仍然遇到問題 Tutorial,也可以看看。

+0

感謝您的回覆!我其實在看過你的教程,並且正在使用它和其他人。我試過,但它沒有工作,平臺只保持靜態,不移動,即使在調試繪製有任何線條指示聯合或任何東西,非常感謝您的幫助 – Farjuan 2013-03-20 02:33:58

+0

嘗試更換不是意味着移動(作爲錨點)與身體PhysiVals.world.GetGroundBody()? – Allan 2013-03-20 03:25:54

+0

是的,試過了,似乎還沒有工作,我試圖讓一些工作像[本] [http://www.actionscript.org/resources/articles/1087/12/Getting-Started-with -Box2D/Page12.html)教程,但我還沒有接近,再一次,結果只是一個靜態框,我試圖改變密度和其他值,但它只是保持靜態 – Farjuan 2013-03-20 04:24:15