1

I managed to create a tree and the program is supposed to only allow users to rotate this tree horizontally.

After looking at the doc, I use the following code

treeNode.physicsBody?.angularVelocityFactor = SCNVector3Make(0, 0, 1.0)

But this didn't do anything, I was still able to rotate the tree in every direction.

What is the correct way to limit node rotation in only horizontal direction?

donkey
  • 4,285
  • 7
  • 42
  • 68
  • That doesn't limit the node's rotation, only the ability of the physics engine to apply rotations. How is the tree's rotation being changed? Can you add a restriction at that point? – Graham Perks Dec 08 '15 at 17:31

1 Answers1

1

Are you really trying to restrict the node's rotation? Or do you want to restrict the camera's rotation?

If the former, you'll have to provide much more detail on your body's physics and structure. An approach using SCNPhysicsHingeJoint seems like it would work.

let joint = SCNPhysicsHingeJoint.init(body: treeNode, 
                                      axis: SCNVector3Make(0, 0, 1.0), 
                                      anchor: SCNVector3Make(xpos, ypos, zpos))

If you're just trying to control the camera, though, you should turn off allowsCameraControl for the SCNView. That's only useful for quick and dirty testing. Then you can implement the technique described here (Rotate SCNCamera node looking at an object around an imaginary sphere) and modified here (SCNCamera limit arcball rotation).

Community
  • 1
  • 1
Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • Sorry, was confused about node's rotation and node camera's movement. I want a particular node to only rotate in horizontal direction. Can I achieve this using camera? – donkey Dec 08 '15 at 17:01
  • 1
    No. But `SCNPhysicsHingeJoint` might be what you're after. From just what you've written in your question, I can't figure out exactly what you're trying to do. – Hal Mueller Dec 08 '15 at 18:25