0

I found this problem, which sounds similar StackOverflow_24965533 but the accepted answer does not work in 9.3.

Example of what I am seeing: Link To Image Here

My code:

func addtopMachete() {
    
    let topMacheteTexture = SKTexture(imageNamed: "machete.png")
    topMacheteSwing = SKSpriteNode(texture: topMacheteTexture)
    topMacheteSwing.name = "topMacheteSwing_Node"
    topMacheteSwing.anchorPoint = CGPoint(x: 0.0, y: 0.0)

    let newX = topMacheteSwing.position.x
    let newY = topMacheteSwing.position.y + (hero.size.height / 2)
    let newLocation = CGPointMake(newX, newY)
    
    topMacheteSwing.position = newLocation
    topMacheteSwing.zRotation = -0.45
    
    let movetopMacheteSwing = SKAction.rotateToAngle(2.75, duration: 3)
    
    let removetopMacheteSwing = SKAction.removeFromParent()
    
    let moveAndRemovetopMacheteSwing = SKAction.sequence([movetopMacheteSwing, removetopMacheteSwing])
    
    topMacheteSwing.runAction(moveAndRemovetopMacheteSwing)
    
    topMacheteSwing.physicsBody = SKPhysicsBody(rectangleOfSize: topMacheteSwing.size, center: CGPointMake(topMacheteSwing.size.width / 2, topMacheteSwing.size.height / 2))
    
    topMacheteSwing.physicsBody!.dynamic = false
    topMacheteSwing.physicsBody!.affectedByGravity = false
    topMacheteSwing.physicsBody!.categoryBitMask = ColliderType.macheteContact.rawValue
    topMacheteSwing.physicsBody!.contactTestBitMask = ColliderType.monsterContact.rawValue | ColliderType.monster2HPContact.rawValue | ColliderType.riotShieldContact.rawValue
    topMacheteSwing.physicsBody!.usesPreciseCollisionDetection = true
    
    let topMacheteJoint = SKPhysicsJointFixed.jointWithBodyA(hero.physicsBody!, bodyB: topMacheteSwing.physicsBody!, anchor: CGPoint(x: CGRectGetMaxX(hero.frame), y: CGRectGetMaxY(hero.frame)))

    hero.addChild(topMacheteSwing)
    self.physicsWorld.addJoint(topMacheteJoint)
}

The hero test UI is just gray circles and when he is pushed I'd like the child node "topMacheteSwing" to move with him. I assumed that pinning them together would do this but it doesn't.

Your help is greatly appreciated.

Community
  • 1
  • 1

1 Answers1

1

So after working through multiple possible solutions I realized the answer was not to use a pinned joint and to instead simply pin the machete to the hero and not use a physics joint at all

topMacheteSwing.physicsBody!.pinned = true