I am creating a leg kicking motion using two physics bodies for now; a body and a leg. I use a pin joint to connect the two bodies, apply angle limits to restrict the leg movement, and apply a torque impulse to kick the leg. All works well.
However, my character also has the ability to jump (just by applying an upward impulse to the body) and this seems to cause a problem to my pin joint's limits. The limits begin to glitch out when the character is upside down, particularly when the character's zRotation moves between PI and -PI, i.e. either side of directly upside down.
This seems strange because the joint limits work well when standing the correct way up. Has anyone ever seen a similar issue when using an SKPhysicsJointPin
object with limits set up?
For completeness, the physics bodies are simple bodyWithRectangleOfSize:
bodies, the leg node is a child of the body node (so rotates with it), and this is how I setup my pin joint:
CGPoint topOfLegAnchor = CGPointMake(0.0, [leg size].height / 2.0);
topOfLegAnchor = [[self scene] convertPoint:topOfLegAnchor fromNode:leg];
SKPhysicsJointPin *pinnedJoint = [SKPhysicsJointPin jointWithBodyA:[body physicsBody]
bodyB:[leg physicsBody]
anchor:topOfLegAnchor];
[pinnedJoint setShouldEnableLimits:YES];
[pinnedJoint setLowerAngleLimit:-M_PI_2];
[pinnedJoint setUpperAngleLimit:0.0];