Spinning prize wheel with touches. In SpriteKit

Is it possible to use applyAngularImpulse, but not exponentially increase the speed of the wheel?
Ideally, I would like the wheel to follow my finger, but setting node.zRotation += atan2f(y2-y1, x2-x1) makes my wheel get out of control. this is what I settled in, but it feels rather awkward:

 - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; SKNode *node = [self nodeAtPoint:location]; CGPoint positionInScene = [touch locationInNode:self]; CGPoint previousPosition = [touch previousLocationInNode:self]; [node.physicsBody applyAngularImpulse:(previousPosition.x - positionInScene.x) * 0.1]; node.physicsBody.angularDamping = 1; } 

scene: https://dl.dropboxusercontent.com/s/gexfburjm1coude/Screen%20Shot%202014-10-21%20at%2010.30.31%20PM.png?dl=0

+4
ios iphone sprite-kit game-physics
source share
1 answer

After applying the pulse:

 [node.physicsBody applyAngularImpulse:theImpulse]; 

Just squeeze the angular speed to the maximum speed, the value of which depends on how fast you want to rotate the wheel:

 const CGFloat maxAngularVelocity = 2.5; node.physicsBody.angularVelocity = MIN(node.physicsBody.angularVelocity, maxAngularVelocity); 
+2
source share

All Articles