ios – 在SpriteKit中使用touchesMoved旋转奖品轮

是否可以使用applyAngularImpulse但不能以指数方式提高车轮的速度?

理想情况下,我想让轮子跟随我的手指,但设置node.zRotation = atan2f(y2-y1,x2-x1)会使我的轮子失去控制.这就是我所确定的,但感觉非常不稳定:

- (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;
}

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

最佳答案 申请你的冲动后:

[node.physicsBody applyAngularImpulse:theImpulse];

只需将角速度钳制到最大速度,其最大速度取决于您想要让车轮旋转的速度:

const CGFloat maxAngularVelocity = 2.5;
node.physicsBody.angularVelocity = MIN(node.physicsBody.angularVelocity, maxAngularVelocity);
点赞