Search code examples
iosswiftscenekitphysics

Why is the physicsBody bigger than visual model in sceneView?


I am working on the game with spaceship flying around earth and destroying objects. I wanted to add some reaction when object hit the spaceship but the contact is detected before it "hit" visual model of the spaceship. I found out that the physicsbody of the node is bigger than visual model. What should I do to set it on the same size? Here's some more info:

  • I created model built of many basic shapes/nodes in SceneKit editor in Xcode

  • I set physics body in the editor with options: dynamic type, default shape, bounding box, scale: 1.

  • There's part of my code that do something with the ship node:

      shipNode = scene.rootNode.childNode(withName: "ship", recursively: true)!
      shipNode.physicsBody!.physicsShape = SCNPhysicsShape(node: shipNode, options: nil)
      shipNode.physicsBody!.categoryBitMask = 4
    

screen of UI of my game, with physicsshapes visible


Solution

  • Just to close this out, we should probably mark it as solved;

    Before, the spaceship was too big so I changed scale of "ship reference" in main scene. In this situation textures got smaller but physicsbody didn't. After your tip, I changed the size of the ship in original .scn file and it solved all problems