Search code examples
sprite-kitskspritenodeskaction

SKSpriteNode won't follow exact path


Issue is described in the image.

to 2: the SKSpriteNode should move again if the blocking node is removed

enter image description here


Solution

  • Based on your objective in your comment:

    If you need to move a node (SKSpriteNode, SKShapeNode etc.) to specific coordinate in your scene, here is your example:

    let boxSize = CGSize(width: 50, height: 50)
    var box = SKShapeNode(rect: CGRect(x: 25, y: 25, width: boxSize.width, height: boxSize.height))
    var point = CGPoint(x: 25, y: 125)
    var animTime:TimeInterval = 2
    box.physicsBody = SKPhysicsBody.init(rectangleOf: boxSize)
    
    let moveToPointAction = SKAction.move(to: point, duration: animTime)
    box.run(moveToPointAction)