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