Search code examples
iosswiftscenekit

How to position a SCNPhysicsBody at the center of a scnnode


I have a SCNNode and a full working physics body attached to it, but the physics bodies center/resting-point is at the bottom of the SCNNode.

Here's what I'm trying to do:

  • Figure out how to position the physics body at the center of the node.
  • Figure out how to control its positioning in some way.

Apple Developer hasn't help me so far. Here is what I have:

let nodePhysicsBody = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(geometry: SCNCapsule(capRadius: 2.0, height: 2.0), options: nil))

I found this init method, but I'm not sure if it will work, or how to implement it.

.init(circleOfRadius r: CGFloat, center: CGPoint()

Solution

  • I'd suggest trying the SCNPhysicsShape init(shapes:transforms:) initializer — rather than constructing a physics shape out of several shapes (and using the transforms parameter to position them relative to one another), you might be able to pass a single shape and a transform that offsets it from the center of the parent coordinate space.