创建关节后是否可以修改引擎的方向?
这是联合的定义:
//Define a prismatic joint
b2PrismaticJointDef jointDef;
b2Vec2 axis = b2Vec2(1.0f, 0.0f);
axis.Normalize(); //Important
jointDef.Initialize(staticBody, body, b2Vec2(0.0f, 0.0f),axis);
jointDef.localAnchorA = b2Vec2(0.0f,0.0f);
jointDef.localAnchorB = body->GetLocalCenter();
jointDef.motorSpeed = 3.0f;
jointDef.maxMotorForce = +200*body->GetMass();
jointDef.enableMotor = true;
jointDef.lowerTranslation = -2.0f;
jointDef.upperTranslation = 3.0f;
jointDef.enableLimit = true;
_horPrismaticJoint = (b2PrismaticJoint*) world->CreateJoint(&jointDef);
在CCTouchesBegan内部,我试图更改力值,但它不起作用:
_horPrismaticJoint->SetMaxMotorForce(-200.0f);
cocos发行版是cocos2d-iphone-1.0.1
答案 0 :(得分:1)
是的,你只需要改变速度(而不是最大力):
joint->SetMotorSpeed( -3.0f );
最大力描述了关节电机的强度,因此它不应该是负的。