Is there a way to remove a physics body in swift 3 ?
All I found was
myNode.phyisicsBody = nil
"Nil cannot be assigned to type SKPhysicsBode"
Just tried the following code in playground, you can
myNode.physicsBody = nil
import UIKit import SpriteKit let spriteNode = SKSpriteNode(imageNamed: "elephant") spriteNode.physicsBody = SKPhysicsBody(texture: spriteNode.texture!, size: spriteNode.texture!.size()) spriteNode.physicsBody = nil // No Error
The default value is nil, which indicates that the node does not participate in the physics simulation at all. If a physics body is provided, when the scene’s physics are simulated, the physics body updates the node’s position and rotates the node.
I would say, check where you initially created the
physicsBody, and make sure it is optional.
SceneObject!.physicsBody! = nil
This cannot work! by using the
! you are telling the compiler that it is not
Change it to
SceneObject!.physicsBody = nil