0

This is the code I have for the two nodes. Declarations not included.

 //paddle node and its physicsbody
    paddle = childNode(withName: "paddle") as! SKSpriteNode
    paddle.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: paddle.size.width,
                                                                         height: paddle.size.height))
    paddle.physicsBody?.isDynamic = false
    paddle.physicsBody?.affectedByGravity = false;
    paddle.physicsBody?.friction = 100
    paddle.physicsBody?.restitution = 0
    //paddle.physicsBody?.linearDamping = 1
    //paddle.physicsBody?.angularDamping = 1

//Second node
rect.position = CGPoint(x: 100, y:500)
        rect.fillColor = UIColor(hue: 215/360, saturation: 49/100, brightness: 54/100, alpha: 1.0)
        rect.strokeColor = UIColor(hue: 215/360, saturation: 49/100, brightness: 54/100, alpha: 1.0)
        rect.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: rect.frame.width, height: rect.frame.height))
        rect.physicsBody?.friction = 0.4
        rect.physicsBody?.restitution = 0
        rect.physicsBody?.mass = 100
        rect.physicsBody?.allowsRotation = true
        rect.physicsBody?.isDynamic = true
        rect.physicsBody?.linearDamping = 0
        rect.physicsBody?.angularDamping = 0
        //rect.physicsBody?.velocity = CGVector(dx: 0, dy: -700)
        rect.physicsBody!.applyImpulse(CGVector(dx: 2.0, dy: -2.0))
        rect.lineWidth = 10
        addChild(rect)

I am not sure if I am asking the right question but I have the rectangular node falling down unto a paddle that can be moved side to side by touch. Once the rect node is on top of the paddle I want it to stay on it while the I move the paddle but it stays pinned and does not move although everything else (gravity, rotation, etc.) works.

Here are the pictures to clarify

https://i.stack.imgur.com/LIqYT.png

https://i.stack.imgur.com/ap6Yy.png

  • This seems to be similar to what you're asking: http://stackoverflow.com/questions/32513802/how-to-make-sprite-sit-on-a-moving-sprite/32517953#32517953 – ZeMoon Feb 25 '17 at 11:41
  • I tried everything in the post but nothing worked :( Its the same concept except I am moving the paddle side to side by touch. for touch: AnyObject in touches { let location = touch.location(in: self) paddle.position.x = location.x } If that makes any difference. I have no clue as to why it won't work. – qkrtjrrnjs Feb 25 '17 at 15:34
  • I think I know why it doesn't work but I don't know how to fix it. It doesn't work if I make it so that the paddle moves by touch. if it automate it, everything works/ – qkrtjrrnjs Feb 25 '17 at 20:35

0 Answers0