Amit Kalra
Amit Kalra

Reputation: 4113

How to make SCNNode spin Horizontally when user spins

I'm trying to figure out how to make a SCNNode rotate ONLY horizontally when a user is spinning the object in that way. Like spinning a basketball on your finger as an example. Is there a way to do that? I haven't been able to figure it out! Sorry if this sounds dumb! I'm new to SceneKit!

Thank you!

Upvotes: 0

Views: 129

Answers (1)

xta
xta

Reputation: 809

You want to apply torque in only the Y axis. See this diagram for the x, y, z axis rotations. https://stackoverflow.com/a/32707673

With your node (assuming you're using swift), you can use

let torque = SCNVector4(x: Float(0), y: Float(1), z: Float(0), w: Float(0.5)) node.physicsBody?.applyTorque(torque, asImpulse: true)

The last value in the SCNVector 4 is the magnitude, so play around with it to find a value that suits you

Upvotes: 0

Related Questions