My goal: To make SKSpriteNode move to another SKSpriteNodes position. (To create a magnet for my sprite game)
Hi, I am trying to get several SKSpriteNodes with the same name in order to move and collide with a node sprite, which they will call it a magnet. I just don’t understand where and how I will do it. I tried using this code, but I left scratches on what to do:func update(_ currentTime: TimeInterval) {
let node = childNode(withName: "specialObstacle")
let magnetLocation = magnet.position
let specialObjectLocation = node?.position
let x = node?.position.x - magnetLocation.x
let y = node?.position.y - magnetLocation.y
}
Note. My arrangement of magnets will change due to the fact that the user will move the magnet around the screen and would like him to continue moving towards the magnet, but I just can’t figure out how to do this.
EDIT 1
, , , , x, , , y - , , , .

- , :
let playerLocation:CGPoint = self.convert(thePlayer.position, from: worldNode)
let location = playerLocation
let nodeSpeed:CGFloat = 3.5
worldNode.enumerateChildNodes(withName: "levelUnit"){
node, stop in
let levelUnit:LevelUnit = node as! LevelUnit
levelUnit.enumerateChildNodes(withName: "specialObstacle"){
node, stop in
let dx = location.x - (node.position.x)
let dy = location.y - (node.position.y)
let angle = atan2(dy, dx)
node.zRotation = angle
let vx = cos(angle) * nodeSpeed
let vy = sin(angle) * nodeSpeed
node.position.x += vx
node.position.y += vy
}
}