I try to convert a game which I started with SpriteKit to Cocos2d V3. I have some problems with the physics though. I create a human like playing figure. The limbs are connected via PinJoints in SpriteKit. I recreated that basic functionality via PivotJoints in Chipmunk. That works as expected.
But I need to add some friction to the joints. Right now they just rotate as fast as possible and even more important I need to limit the rotation angle of the joints. As you can imagine, most people can’t rotate their shoulders freely by 360 degrees. ;)
AFAIK I should use ChipmunkRotaryLimitJoint and ChipmunkGearJoint to achieve that. My problem is, that I can’t make it work because I don’t know how to attach them correctly. This is my code right now:
- (CCPhysicsJoint *)createPinJointWithBodyA:(CCPhysicsBody *)bodyA
bodyB:(CCPhysicsBody *)bodyB
anchor:(CGPoint)anchor
friction:(CGFloat)friction
lowerLimit:(CGFloat)lowerLimit
upperLimit:(CGFloat)upperLimit
{
CCPhysicsJoint *pin = [CCPhysicsJoint
connectedPivotJointWithBodyA:bodyA
bodyB:bodyB
anchorA:anchor];
ChipmunkRotaryLimitJoint *limitJoint = [ChipmunkRotaryLimitJoint
rotaryLimitJointWithBodyA:bodyA.body
bodyB:bodyB.body
min:CC_DEGREES_TO_RADIANS(lowerLimit)
max:CC_DEGREES_TO_RADIANS(upperLimit)];
ChipmunkGearJoint *gearJoint = [ChipmunkGearJoint
gearJointWithBodyA:bodyA.body
bodyB:bodyB.body
phase:0.5
ratio:0.5];
return pin;
}
(The values in the gearJoint call are just place holders!)
Does anybody have an idea how this is supposed to work? I found some things via Google, but all tutorials assume, that I use chipmunk in some other environment. Do I have to create my own CCPhysicJoint implementation for these limit and gear joints?
Thanks and best wishes, Thomas