Karlos Zafra
Karlos Zafra

Reputation: 248

Change PrismaticJoint engine direction

Is it possible to modify the direction of the engine after the joint is created?

This is the definition of a joint:

//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);

Inside CCTouchesBegan I tried to change the force value but it's not working:

    _horPrismaticJoint->SetMaxMotorForce(-200.0f);

The cocos distribution is cocos2d-iphone-1.0.1

Upvotes: 0

Views: 302

Answers (1)

iforce2d
iforce2d

Reputation: 8262

Yes, you just need to change the speed (not the max force):

joint->SetMotorSpeed( -3.0f );

The max force describes how strong the joint motor is, so it should not be negative.

Upvotes: 1

Related Questions