是否可以使用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;
}
答案 0 :(得分:2)
应用你的冲动后:
[node.physicsBody applyAngularImpulse:theImpulse];
只需将角速度钳制到最大速度,其速度取决于您想要让车轮旋转的速度:
const CGFloat maxAngularVelocity = 2.5;
node.physicsBody.angularVelocity = MIN(node.physicsBody.angularVelocity, maxAngularVelocity);