Swift - sprite kit - make SKPhysicsJointPin have less motion

186 views Asked by At

I'm trying to create a snake with multiple body parts that moves left and right. Im using a pin, but upon the snake stopping, the body keeps moving and doesn't stop. I've messed around with the max and min angles, and the torque, but nothing seems to work. Should I use a different type of joint?

1

There are 1 answers

0
drew On

Sorry i cant log into my other account, but heres the code. Basically the second part just wobbles a lot. I wish to add 7-8 parts, but they just keep on wobbling, especially after moving "head". i would like a fluid "swoop" motion when i move the snake.

    self.physicsWorld.gravity = CGVectorMake(0, -100)
    self.physicsWorld.contactDelegate = self

    head.size = CGSize(width: 25,height: 25)
    head.physicsBody = SKPhysicsBody(texture: head.texture, size: head.size)
    head.position = CGPointMake(100,400)
    head.anchorPoint = CGPoint(x: 0.5, y: 1)
    head.physicsBody!.dynamic = false
    head.zPosition = 3
    self.addChild(head)

    var p1 = SKSpriteNode(imageNamed: "snakeBodyPart.png")
    p1.size = CGSize(width: 25,height: 25)
    p1.physicsBody = SKPhysicsBody(texture: p1.texture, size: p1.size)
    p1.position = CGPointMake(100,380)
    p1.anchorPoint = CGPoint(x: 0.5, y: 1)
    p1.physicsBody!.dynamic = true
    addChild(p1)

    var joint = SKPhysicsJointPin.jointWithBodyA(head.physicsBody, bodyB: p1.physicsBody, anchor: CGPoint(x: CGRectGetMidX(head.frame), y: CGRectGetMinY(head.frame) + 10))
    joint.upperAngleLimit = 0.1
    joint.rotationSpeed = 0.1
    self.physicsWorld.addJoint(joint)