0

I created a rope based off this tutorial, except my rope has one ball attached on each end of the rope.

High Level: This is how they create the rope.

  1. create an array of SKNodes
  2. append each rope segment (node) to the array
  3. add each node to the screen
  4. join each node together to form a rope
  5. (Then I add a ball on each end of the rope)

In my program I move the ball around and basically swing the rope around kind of like a stretchy pendulum.

Here's my issue: If I swing the rope around very hard, the rope stretches too much! How can I decrease the amount the rope stretches? I don't see a method to decrease the elasticity of the body.

If there is any other information that will be useful please let me know! Thanks in advance

Sami
  • 579
  • 5
  • 25

1 Answers1

2

You can try these two methods. The first method is to increase the property frictionTorque of SKPhysicsJointPin class.

The range of values is from 0.0 to 1.0. The default value is 0.0. If a value greater than the default is specified, friction is applied to reduce the object’s angular velocity around the pin.

An example for the tutorial you followed, before adding a joint to the scene, modify frictionTorque:

for i in 1...length {
    let nodeA = ropeSegments[i - 1]
    let nodeB = ropeSegments[i]
    let joint = SKPhysicsJointPin.jointWithBodyA(nodeA.physicsBody!, bodyB: nodeB.physicsBody!,
        anchor: CGPointMake(CGRectGetMidX(nodeA.frame), CGRectGetMinY(nodeA.frame)))
    joint.frictionTorque = 0.5    // Add this line

    scene.physicsWorld.addJoint(joint)
}

The second method is to limit the swing angle of the pin joint. After enabling shouldEnableLimits, adjust lowerAngleLimit and upperAngleLimit in radians.

Read more about SKPhysicsJointPin Class Reference for Determining the Characteristics of the Pin Joint.

WangYudong
  • 4,335
  • 4
  • 32
  • 54
  • Thanks for the response. I just tried changing the `frictionTorque`, turning on `shouldEnableLimits` and adjusting the upper/lower limits. Nothing changed, any other ideas? – Sami Sep 30 '15 at 16:24
  • I was able to figure it out! Changing the density of the rope was able to solve the stretching issue – Sami Sep 30 '15 at 20:51