Game Development Reference
In-Depth Information
NSLog(@"Head position %@",
NSStringFromCGPoint(head.position));
SKPhysicsJointLimit* pin =[SKPhysicsJointLimit
jointWithBodyA:backBone.physicsBody
bodyB:head.physicsBody anchorA:head.position
anchorB:CGPointMake(backBone.position.x,
backBone.position.y+backBone.size.height/2.0)];
pin.maxLength = 100;
[scene.physicsWorld addJoint:pin];
[NSTimer scheduledTimerWithTimeInterval:5
target:self selector:@selector(applyImpulseUpwards:)
userInfo:@{@"body":head.physicsBody,@"impulse":@(50)}
repeats:YES];
}
In the second last section, we are applying the limit joint on both the physics bod-
ies that we have created. To apply a limit joint, we have to pass both the bodies
along with the anchor points that create the joint. Now, when the joint object is
initialized, we can add the joint to the physics world.
As we have seen earlier in sliding joint, an extra impulse has been applied on one
of the bodies. Similarly, here also we have to apply the impulse on the square
body to test the limit joint behavior.
16. Now, replace the createSpringJointOnScene function call with cre-
ateLimitJointOnScene . Add the following code at the end of the init
function:
[self createLimitJointOnScene:self];
17. Now compile and run the project and you should be able to see both the physics
bodies sliding over each other.
Search WWH ::




Custom Search