4
votes

Using swift, I am trying to make a SKSpriteNode (that doesn't have a physics body) follow another SKSpriteNode that has a physics body. I want this to be done when there is contact between the sprite with a physics body and another physics body. I read about setting SKContsraints but these have a range and often fall out or vary. I want the sprite to be followed precisely. How can this be done?

1
What kind of effect do you want? Do you want it to be like a stick is connecting them or do you want one of them to follow closely behind,ecentually hitting the sprite if it stays still?J.Doe

1 Answers

0
votes

Make sure your scene is a SKPhysicsContactDelegate. Then put this in your didBeginContact() method.

nodeWithoutPhysicsbody.position = nodeWithPhysicsbody.position

If you want the node without the physics body to always follow the node with the physics body, then put that line of code in the update method.